gutentags / system

Flexible module and resource system
BSD 3-Clause "New" or "Revised" License
12 stars 4 forks source link

Support workers #4

Open kriskowal opened 8 years ago

kriskowal commented 8 years ago

This would look like further data- attributes on a script tag that would build a set of entry points for workers. Every worker including the main thread would be able to "spawn" any worker as effectively a child process. The interface for the worker needs to be identical between use in Node.js, in the browser during development, in the browser with a bundle. Each worker would produce a separate bundle and be cross-referenced by relative URL so they can execute each other.

Punting ideas for shared common bundles and service workers as out of scope for minimum viable workers.

kriskowal commented 7 years ago

Also, IO channels need to be consistent between use in Node.js, use in bundler in Node.js, use in Browser during development, use in Browser with bundles. There needs to be a convention for exposing the "executables" to the script and how to expose the communication channel to the worker. It might be that workers and their executors need a conventionally exported main() that the module loader calls.

<script src="boot.js" data-worker="./worker" data-import="./entry"></script>
// entry.js
var child = new require.Worker("./worker");

// worker.js
module.exports = function main(parent) {
    parent.addEventListener("message", ...);
};