UNPKG

keep-trying

Version:

A function for creating retryable promises with configurable limit and backoff.

18 lines (17 loc) 514 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const randomInt = (max) => Math.floor(Math.random() * Math.floor(max)); exports.strategies = { none: (time) => time, full: (time) => randomInt(time), equal: (time) => { const halvedBackoff = time / 2; return halvedBackoff + randomInt(halvedBackoff); } }; exports.choose = (strategy) => { if (typeof strategy === 'function') { return strategy; } return exports.strategies[strategy]; };