javascript - How to call shared worker from the web worker? -


is possible call shared worker web worker?

could please give me example.

in case have few web workers , need share singleton service between them.

the sharedworker constructor not available within workerglobalscope, not able construct instance in iframe or window.

what can is, create messagechannel each of workers, , use communicate between worker , sharedworker. though doing negate need actual sharedworker, since use single worker instead.

example:

var numworkers = 4; var sharedworker = new worker("worker-shared.js");  for(var = 0; < numworkers; i++) {   var dedicatedworker = new worker("worker-dedicated.js");   var channel = new messagechannel();   dedicatedworker.postmessage({sharedworkerport: channel.port1}, [channel.port1]);   sharedworker.postmessage({workerport: channel.port2}, [channel.port2]); } 

demo


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -