Skip to content

yunnysunny/threads

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published