@cognigy/rest-api-client
Version:
Cognigy REST-Client
22 lines • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.exponentialDelay = void 0;
/**
* 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
*/
function exponentialDelay(retryNumber = 0) {
const delayInSeconds = Math.pow(2, retryNumber) * 1000;
const randomMs = ~~(1000 * Math.random());
return delayInSeconds + randomMs;
}
exports.exponentialDelay = exponentialDelay;
//# sourceMappingURL=exponentialDelay.js.map