1.0.1 • Published 6 years ago

island-worker v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

island-worker Build Status Coverage Status

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

License

MIT © Harvey Zack

1.0.1

6 years ago

1.0.0

6 years ago