0.2.1 • Published 10 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
producerto generate input for an asyncconsumer.producermight perform an HTTP request, whileconsumerstores 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 prankcallAPI
License
MIT
Tests
npm test
