@yunnysunny/threads

0.2.1 • Public • Published

threads

build status Test coverage GitHub license node version

NPM

Thread util in Node.js. It's only test on node 12+.

Install

yarn add @yunnysunny/threads

Usage

NoneBlockingThreadPool

const {NoneBlockingThreadPool: ThreadPool} = require('@yunnysunny/threads');

const poolStr = new ThreadPool({
    poolSize: 5,
    script: path.join(__dirname, '../scripts/str_worker.js')
});
poolStr.send('test');
poolStr.on(ThreadPool.EVENT_NEW_MESSAGE, function(msg) {
    //process msg
});
poolStr.on(ThreadPool.EVENT_WORKER_ERROR, function(err, threadId) {
    //show error message
});

BlockingThreadPool

const {NoneBlockingThreadPool: ThreadPool} = require('@yunnysunny/threads');
const POOL_SIZE = 5;
const poolStr = new ThreadPool({
    poolSize: POOL_SIZE,
    script: path.join(__dirname, '../scripts/str_worker.js')
});
poolStr.send({data: 'xx', callback: function(err, str) {
    //todo next process
}});
poolStr.on(ThreadPool.EVENT_WORKER_ERROR, function(err, threadId) {
    //show error message
});

Readme

Keywords

Package Sidebar

Install

npm i @yunnysunny/threads

Weekly Downloads

2

Version

0.2.1

License

MIT

Unpacked Size

32.4 kB

Total Files

16

Last publish

Collaborators

  • whyun-master