@belsrc/worker-promise

    0.4.0 • Public • Published

    Worker Promise

    Simple little Promise wrapper for WebWorkers. Make your workers pinky swear.

    Build Status Maintainability Code Coverage Known Vulnerabilities Last Commit PRs Welcome

    Install

    npm i -s @belsrc/worker-promise
    

    Use

    // Example using webpack and worker-loader
    import workerPromise from '@belsrc/worker-promise';
    import Worker from './process.worker';
    
    const worker = new Worker();
    
    workerPromise(worker, { count: 500000 }).then(res => console.log(res));

    also supports callbacks using the optional third parameter.

    workerPromise(webworker, value[, callback])

    with the callback being

    function(error, value)

    I don't advise using with async..await as it still blocks.

    // async-await
    const res = await workerPromise(worker, { count: 500000 });
    console.log(res);
    // calling worker
    // processing: 2136.183837890625ms
    // {error: null, data: Array(41538)}
    // back on the main thread
    
    // promise-then
    workerPromise(worker, { count: 500000 }).then(res => console.log(res));
    // calling worker
    // back on the main thread
    // processing: 2149.153076171875ms
    // {error: null, data: Array(41538)}
    
    // callback
    const logRes = (err, res) => console.log(res);
    workerPromise(worker, { count: 500000 }, logRes);
    // calling worker
    // back on the main thread
    // processing: 2131.60205078125ms
    // {error: null, data: Array(41538)}

    LICENCE

    MIT

    Install

    npm i @belsrc/worker-promise

    DownloadsWeekly Downloads

    61

    Version

    0.4.0

    License

    MIT

    Unpacked Size

    7.46 kB

    Total Files

    5

    Last publish

    Collaborators

    • belsrc