@cognigy/rest-api-client
Version:
Cognigy REST-Client
18 lines • 933 B
JavaScript
/**
* Exponential backoff is the process of a client periodically retrying a
* failed request over an increasing amount of time. It is a standard error
* handling strategy for network applications. The Core Reporting API is
* designed with the expectation that clients which choose to retry failed
* requests do so using exponential backoff. Besides being "required", using
* exponential backoff increases the efficiency of bandwidth usage, reduces
* the number of requests required to get a successful response, and
* maximizes the throughput of requests in concurrent environments.
*
* @see https://developers.google.com/analytics/devguides/reporting/core/v3/errors#backoff
*/
export function exponentialDelay(retryNumber = 0) {
const delayInSeconds = Math.pow(2, retryNumber) * 1000;
const randomMs = ~~(1000 * Math.random());
return delayInSeconds + randomMs;
}
//# sourceMappingURL=exponentialDelay.js.map