Promisable WEB Worker Runner
Run task on web worker and retrieve the result, simply by Promise api.
How to use it
WorkersManager
Inside the main script, import and initialize a // include WorkersManager.js firstvar workersManager = ;
ActualWorker
with a work
method
Inside the worker executive script, import and initialize a There're two ways to initialize a ActualWorker
:
- Directly pass
work
method to constructor:
javascript
// include ActualWorker.js first
var worker = new ActualWorker({work: fnDoWork});
2. Extend to a sub class of `ActualWorker` (by es6 js):
```javascript
// include ActualWorker.js first
class RealWorker extends ActualWorker {
work: fnDoWork
}
var worker = new RealWorker();
WorkersManager
to run work. E.g.:
Use workersManager ;
API
// Create a new worker and let it do the work with specified data// @returns Promise with work output data if succeedsWorkersManagerprototype
// Receive work input and produce direct output or Promise for aync// @returns * | Promise with work output data if succeedsActualWorkerprototype