0.2.1 • Published 9 years ago
prankcall v0.2.1
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
Example
Use an async
producer
to generate input for an asyncconsumer
.producer
might perform an HTTP request, whileconsumer
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 install prankcall
API
License
MIT
Tests
npm test