tc39 / proposal-module-expressions

https://tc39.es/proposal-module-expressions/
MIT License
438 stars 18 forks source link

A different method instead of re-using post-message #33

Closed prateekbh closed 3 years ago

prateekbh commented 3 years ago

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 3 years ago

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