@takeshape/util
Advanced tools
Comparing version 5.54.1 to 6.8.0
export const delay = (timeout, value) => new Promise(resolve => { | ||
setTimeout(resolve, timeout, value); | ||
}); | ||
}); | ||
function randomInt(minimum, maximum) { | ||
return Math.floor(Math.random() * (maximum - minimum + 1) + minimum); | ||
} // Decorrelated jitter backoff: | ||
// https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ | ||
export async function backoff(baseDelay, maxDelay, attempt = { | ||
num: 1, | ||
lastDelay: 0 | ||
}) { | ||
const msec = Math.min(maxDelay, randomInt(baseDelay, (attempt.lastDelay || baseDelay) * 3)); | ||
await delay(msec); | ||
return { | ||
num: attempt.num + 1, | ||
lastDelay: msec | ||
}; | ||
} |
export declare const delay: <T>(timeout: number, value?: T | undefined) => Promise<T>; | ||
export interface Attempt { | ||
num: number; | ||
lastDelay: number; | ||
} | ||
export declare function backoff(baseDelay: number, maxDelay: number, attempt?: Attempt): Promise<Attempt>; |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.backoff = backoff; | ||
exports.delay = void 0; | ||
@@ -13,2 +14,20 @@ | ||
exports.delay = delay; | ||
exports.delay = delay; | ||
function randomInt(minimum, maximum) { | ||
return Math.floor(Math.random() * (maximum - minimum + 1) + minimum); | ||
} // Decorrelated jitter backoff: | ||
// https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ | ||
async function backoff(baseDelay, maxDelay, attempt = { | ||
num: 1, | ||
lastDelay: 0 | ||
}) { | ||
const msec = Math.min(maxDelay, randomInt(baseDelay, (attempt.lastDelay || baseDelay) * 3)); | ||
await delay(msec); | ||
return { | ||
num: attempt.num + 1, | ||
lastDelay: msec | ||
}; | ||
} |
{ | ||
"name": "@takeshape/util", | ||
"version": "5.54.1", | ||
"version": "6.8.0", | ||
"homepage": "https://www.takeshape.io", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13849
301