Create consumers that expire after a certain time period or task count that are schedulised to be used in a round robin fashion
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
README.md
index.js
package.json

README.md

Round Robin Dependency Status Build Status Coverage Status

Create consumers that expire after a certain time period or task count that are scheduled to be used in a round robin fashion.

How to

var RoundRobin = require("round-robin").RoundRobin

var scheduler = new RoundRobin({

  // Create a new thing to do tasks
  spinUp: function (cb) {
    var thing = {doTask: function() {}, destroy: function() {}};
    cb(null, thing); // Remember to call the callback when ready
  },

  // Tear down the thing, it won't be used again!
  spinDown: function(thing, cb) {
    thing.destroy();
    cb(); // Remember to call the callback when done!
  },

  maxUp: 10, // Allow at most 10 things to be spun up at once
  maxUsage: 100, // Allow the thing to be used 100 times before it is spun down
  maxAge: 1000 * 60 * 60, // Allow the thing to live for an hour before it is spun down
  lazySpinDown: true // Spin down lazily (avoids the polling interval processing)
});

// Use the scheduler to get a thing and perform a task every second
var intervalId = setInterval(function () {
  scheduler.get(function (er, thing) {
    thing.doTask();
    scheduler.ret(thing); // Return the thing so the scheduler can hand it out again
  })
}, 1000);

// Finish doing tasks after 5 minutes
setTimeout(function () {
  clearInterval(intervalId);

  scheduler.destroy(function (er) {
    console.log("Finished doing tasks");
  })
}, 1000 * 60 * 5);