This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

worker-q

1.0.1 • Public • Published

worker q

Introduction

This is a Node.js based module for queuing asynchronous work.

Disclaimer: Please don't share WorkerQ objects across threads; actions are not designed to be thread safe!

Dependencies

None (it uses setTimeout() for async)

Examples

Do an npm install worker-q.

var WorkerQ = require("worker-q");
 
var waitThenCallback = function(wait, callback) {
  setTimeout(callback, wait, wait);
};
 
//1 is serial execution. 2+ is parallel. Experiment with different numbers
var activeJobsLimit = 2;
var myAwesomeQueue = new WorkerQ(activeJobsLimit);
 
var myAwesomeWork = [
  function(success, failure) {
    waitThenCallback(3000, success);
  }, function(success, failure) {
    waitThenCallback(2000, success);
  }, function(success, failure) {
    waitThenCallback(1000, success);
  }, function(success, failure) {
    failure("we wanted it to");
  }
];
 
myAwesomeQueue.jobSucceeds(function(wait) {
  console.log("waited " + wait + " ms");
  if (myAwesomeWork.length > 0) {
    myAwesomeQueue.add(myAwesomeWork.shift());
  }
});
myAwesomeQueue.jobFails(function(reason) {
  console.log("a job failed because " + reason);
});
 
//note that only 2 jobs are queued initially. If you increase the
// activeJobsLimit from 2, then add more jobs to the queue from the start
myAwesomeQueue.add(myAwesomeWork.shift());
myAwesomeQueue.add(myAwesomeWork.shift());
myAwesomeQueue.start();

License

Apache 2

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Published

Version History

  • Version
    Downloads (Last 7 Days)
    • Published

Package Sidebar

Install

npm i worker-q

Weekly Downloads

1

Version

1.0.1

License

Apache-2.0

Last publish

Collaborators

  • tombailey