tiny-worker icon indicating copy to clipboard operation
tiny-worker copied to clipboard

Source from http://

Open avaer opened this issue 7 years ago • 4 comments

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?

avaer avatar Jan 20 '18 12:01 avaer

sounds like a gap that should be fixed

avoidwork avatar Jan 21 '18 10:01 avoidwork

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 avatar Apr 12 '19 03:04 pankajvishwani

@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.

avoidwork avatar Apr 12 '19 11:04 avoidwork

ugh, misclicked in the ui.

avoidwork avatar Apr 12 '19 11:04 avoidwork