SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Range = length => [...Array(length).keys()];
  2. const data = Range(10000);            
  3. const workers = Range(5).map(_ => new Worker('worker.js'));
  4. for(let worker of workers){
  5.   worker.onmessage = res => {
  6.     if(data.length)
  7.         res.target.postMessage(data.shift());
  8.     else
  9.         res.target.terminate();
  10.   };
  11.   worker.postMessage(data.shift());
  12. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top