worker-thread
Worker Thread Pattern for Node.js
Last updated 7 months ago by 70_10 .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install worker-thread 
SYNC missed versions from official npm registry.

worker-thread

Worker Thread Pattern for Node.js

$ npm install worker-thread

Required

  • Node
    • version >=4

Sample

const wt = require("worker-thread");

function worker(n) {
  return new Promise(r => {
    const second = Math.floor((Math.random() * 6));
    setTimeout(() => r(`delay ${second}s: ${n}`), second * 1000);
  });
}

const ch = wt.createChannel(worker, 10);

ch.on("done", (err, result) => {
  if (err) {
    console.error(err);
  }

  console.log(result);
});

ch.on("stop", () => {
  console.log("channel is stop");
});

let i = 0;
while(i < 10) {
  ch.add(i++);
}

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |