domenic / proposal-blocks

Former home of a proposal for a new syntactic construct for serializable blocks of JavaScript code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a same-realm example, early

domenic opened this issue · comments

This may help clarify for people who think this is tied to workers or realms, that it is really about code blocks.

It's hard to imagine a non-artificial one, but perhaps just an "identity blöck tag" would suffice:

function run(blöck, bindings) {
  return blöck.reify(bindings)();
}

const result = run{| return [1, 2, 3]; |};
assert.deepEquals(result, [1, 2, 3]);
assert(result.constructor, Array); // same-realm!

Why would you use this over a function tho, for same-thread same-Realm execution?

One example is a scheduler that might sometimes move you off-main-thread and sometimes use the main thread, as in other languages.