More ergonomic access to modules that are in workers #72
Description
(Note: This seems like something that would be handled in a separate, follow-up proposal, but I'm just posting here to make sure the door is left open to allowing this sort of thing, if possible.)
Some relevant discussion: whatwg/html#6911 (comment) (not required reading for this issue, but useful for context)
As I mentioned in that thread, a big pain point with workers is the postMessage/onmessage wrangling required to take some functions off the main thread and put them in a worker (e.g. tracking message IDs so I can get a simple promisified API to the functions that are now in the worker). This can of course be handled by a library like comlink, but it seems like a common enough pattern to warrant consideration here.
Some example/pseudo code from that thread:
const worker = new Worker();
const workerModule = await worker.addModule(module { export function sum(a, b) { return a+b } });
const sum = await workerModule.sum(1, 2);
Please consider that as very-pseudo code - I'm not proposing any concrete API here, just giving an example of an ergonomic way of using the in-worker module from the main thread. There would of course also be technical details to iron out (e.g. regarding behavior for non-serializable stuff).
I'm wondering if this proposal is in a position to potentially allow something like that in the future?
Activity