UNPKG

http-retrier

Version:

20 lines (19 loc) 748 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.wait = void 0; /** * * @param {number} ms - The delay in milliseconds * @param {number} attempt - The current attempt number * @param {boolean} exponentialBackoff - Whether to use exponential backoff for the delay * @returns {Promise<void>} - A promise that resolves after the specified delay */ function wait(ms, attempt, exponentialBackoff = true) { ms = attempt <= 1 ? 0 : exponentialBackoff ? Math.pow(2, attempt) * ms : ms; if (ms > 10000) ms = 10000; // cap the max delay to 10 seconds if (ms < 0) ms = 0; // cap the min delay to 0 seconds return new Promise(resolve => setTimeout(resolve, ms)); } exports.wait = wait;