promise-poller
Version:
A basic poller built on top of promises
31 lines (30 loc) • 733 B
JavaScript
;
var strategies = {
'fixed-interval': {
defaults: {
interval: 1000
},
getNextInterval: function getNextInterval(count, options) {
return options.interval;
}
},
'linear-backoff': {
defaults: {
start: 1000,
increment: 1000
},
getNextInterval: function getNextInterval(count, options) {
return options.start + options.increment * count;
}
},
'exponential-backoff': {
defaults: {
min: 1000,
max: 30000
},
getNextInterval: function getNextInterval(count, options) {
return Math.min(options.max, Math.round(Math.random() * (Math.pow(2, count) * 1000 - options.min) + options.min));
}
}
};
module.exports = strategies;