workaholic-js

0.1.2 • Public • Published

workaholic-js

web-worker API for multi thread programming on browser

Version Build status

Install

Install with npm:

npm install workaholic-js

API - Create workers and connect automatically

 
   var w = Workers( );
   Promise.all([ w.cmd(()=>1 + 2), w.cmd(()=>3 + 4), w.cmd(()=>5 + 6), w.cmd(()=>7 + 8), w.cmd(()=>9) ])
     .then(rd=>console.log('Completed!', rd)); // => [3, 7, 11, 15, 9]
   
   // for Compare:[by workers] ... NO DISPLAY FREEZE
   var s = Date.now(); Promise.resolve().then(()=>w.cmd({ var i = 0; while(< 10000000000) i += 1; return i; })
     .then(r=>console.log('OK', Date.now() - s + 'ms', r));
   // for Compare:[by on-display] ... DISPLAY FREEZE
   var s = Date.now(); Promise.resolve().then(()=>{ var i = 0; while(< 10000000000) i += 1; return i; })
     .then(r=>console.log('OK', Date.now() - s + 'ms', r));
   
   // NOTE:
   // It tooks 1~2ms to pass any operation to tunnel to a worker. It means that worker should owe ONLY some BATCH process which hangs
   // user operation.
   
   // To debug mode
   w.setDebug('ISO');
   // Off
   w.setDebug(0);
   
   // remove workers
   w.close();
   

Readme

Keywords

Package Sidebar

Install

npm i workaholic-js

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

23.7 kB

Total Files

6

Last publish

Collaborators

  • ystskm