1.0.1 • Published 6 years ago
island-worker v1.0.1
island-worker
An utility of web workers
Install
$ npm install island-worker
Usage
import IWorker from 'island-worker';
// By default, a worker named 'default' is created
var workers = new IWorker(args => {
return args[0];
});
// By default execute a worker named 'default'
workers.run(['default']).then(console.log).catch(console.error);
// Or use async/await
// (async () => {
// console.log(await workers.run(['default']));
// })();
// Add a custom worker
workers.add('custom', args => {
return args[0];
});
// Execute a custom worker
workers.run('custom', ['custom']).then(console.log).catch(console.error);
// Execute all workers
setTimeout(() => {
workers.runAll(['runAll']).then(console.log).catch(console.error);
}, 200);
// By default, a worker named 'default' is stopped
setTimeout(() => {
workers.kill();
workers.run(['kill']).then(console.log).catch(console.error);
}, 400);
// Stop all workers
setTimeout(() => {
workers.killAll();
workers.runAll(['killAll']).then(console.log).catch(console.error);
}, 600);
Related
- simple-web-worker - An utility to simplify the use of web workers
License
MIT © Harvey Zack