tiny-worker
tiny-worker copied to clipboard
Source from http://
My use case requires sourcing workers from remote HTTP, like the browser Worker.
Seems doable to make that work on either the master or child side, though postMessage might need to buffer up on the async in that case.
https://github.com/avoidwork/tiny-worker/blob/master/lib/index.js#L24 https://github.com/avoidwork/tiny-worker/blob/master/lib/worker.js#L18
Thoughts?
sounds like a gap that should be fixed
One way to solve this is by providing capability where developer can pass source code itself. In your case, you can fetch source from remote http and then pass source while creating worker.
PR: https://github.com/avoidwork/tiny-worker/pull/30 If merged, you will be able to do the following:
const source = `
onmessage = function (ev) {
postMessage(ev.data);
};
`;
var Worker = require("tiny-worker");
var worker = new Worker(source, [], { source: true });
worker.onmessage = function(ev) {
console.log(ev.data);
worker.terminate();
};
worker.postMessage("Hello World!");
@pankajvishwani that scenario is midway between 2 existing solutions, being the file on disk or the function. The solution is to simply fetch the remote file and process as if it was a local script.
ugh, misclicked in the ui.