workers-queue

1.0.1 • Public • Published

workersQueue

tasks queue for multiple workers, works with node@^4.x.x

howto

let worker1 = function(task) {
  return new Promise((resolve, reject) {
    //do the heavy work in webworker/forked process
  })
};
let worker2 = function(task) {
  return new Promise((resolve, reject) {
    //do the heavy work in webworker/forked process
  })
};
let queue = new WorkersQueue([worker1, worker2]);

queue.addTask(task).then(function(result) {
  //get result
});
queue.addTask(task).then(function(result) {
 //get result
});

all tasks will be distributed between free workers, and stack up in the pending queue

API

###class:WorkersQueue -

queue.addTask(task) - Promise

Returns a promise that resolved as soon as task is done. If it fails - promise is rejected.

queue.pendingTasks - Array

The array of pending tasks, if workers are not handling the load.

queue.running - Array

The array of current workers statuses - [false, true, false] means that first and last workers are free.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    0
  • 1.0.0
    1

Package Sidebar

Install

npm i workers-queue

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • edjafarov