Not a Propaganda Machine

    @yunnysunny/threads

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

    Keywords

    Install

    npm i @yunnysunny/threads

    DownloadsWeekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    18.1 kB

    Total Files

    14

    Last publish

    Collaborators

    • yunnysunny