domenic / proposal-blocks

Former home of a proposal for a new syntactic construct for serializable blocks of JavaScript code
215 stars 5 forks source link

maybe fork() is a good analogy? #12

Open samuelgoto opened 6 years ago

samuelgoto commented 6 years ago

I'm wondering if fork() is a good analogy of what you are trying to accomplish:

if (fork()) {
  // executes in the parent
} else {
  // executes in the child
  // communicates with the parent through pipes
}

Interestingly, though:

Surprisingly, though:

Exactly how that translates to javascript is unclear, but here are a few ideas along these lines:

if (fork()) {
  // code runs in a worker and doesn't share memory
}

or maybe

fork() {
   // maybe this looks different/weird enough that would give the right
  // signal of what's going on?
}

or maybe

new Worker() {
  // ...
}

Here is what it could look like in locu:

<button onclick="fork() { localStorage.write('expansive!') }">write</button>

maybe this is too much to ask and hard to make the distinction, but hey, at least there is "some" precedence :)

j-f1 commented 6 years ago

How about fork { ... }, which would act like do { ... } except it would return a Promise for a structured-clone version of the result?