node package manager

prankcall

prankcall

Call a node.js generator with backoff and other customization

  • Configure exponential backoff via node-retry options
  • Call the generator just once or repeatedly based on custom logic
  • Optionally define another generator to receive results
  • Sleep between successful calls
  • Combine with modules like:
  • Observe retry events for logging

Build Status

Example

Use an async producer to generate input for an async consumer. producer might perform an HTTP request, while consumer stores the result in a database, job queue, etc.

function *producer() {
  var data = yield producerWork();
  // ... 
  return data;
}
 
function *consumer(dataFromProducer) {
  yield consumerWork(dataFromProducer);
  return shouldProducerRunAgain(); // {boolean} 
}
 
co(function *() {
  var prankcall = require('prankcall').create();
  yield prankcall
    .sleep(1500) // Wait 1.5s after each successful `producer` call 
    .retry({
      retries: 5,
      factor: 3,
      minTimeout: 1 * 1000,
      maxTimeout: 60 * 1000,
      randomize: true
    })
    .recv(consumer);
    .send(producer);
})();

See more examples.

Installation

NPM

NPM

npm install prankcall

API

License

MIT

Tests

npm test