tc39/proposal-module-expressions

A different method instead of re-using post-message

prateekbh opened this issue · 1 comments

Sorry if this was already discussed or if this feels like bikeshedding.

re-using postMessage seems a bit confusing, would it make it a bit more readable if it were
worker.execute(module { export function fn() { return "hello!" } })?

execute/run/etc

Keen to hear your thoughts

surma commented

That’s a much more invasive change to the HTML spec and needs a lot more thought: How was worker initialized? What does execute actually do? What is the return value of execute()?

If it does what I think you want it to do, it can easily be built on top of the existing postMessage() infrastructure.

That being said, at some point I would like to investigate something like a proper ModuleWorker:

const api = new ModuleWorker(module {
  export function add(a, b) {
    return a + b;
  }
});
console.log(await api.add(40, 2)); // Logs 42