0.2.1 • Published 1 year ago

@yunnysunny/threads v0.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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
});
0.2.1

1 year ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago