carina
Version:
A NodeJS and Browser compatible client for Mixer.com's constellation socket.
26 lines • 1.09 kB
JavaScript
/**
* The ExponentialReconnectionPolicy is a policy which reconnects the socket
* on a delay specified by the equation min(maxDelay, attempts^2 * baseDelay).
*/
var ExponentialReconnectionPolicy = /** @class */ (function () {
/**
* @param {Number} maxDelay maximum duration to wait between reconnection attempts
* @param {Number} baseDelay delay, in milliseconds, to use in
*/
function ExponentialReconnectionPolicy(maxDelay, baseDelay) {
if (maxDelay === void 0) { maxDelay = 20 * 1000; }
if (baseDelay === void 0) { baseDelay = 500; }
this.maxDelay = maxDelay;
this.baseDelay = baseDelay;
this.retries = 0;
}
ExponentialReconnectionPolicy.prototype.next = function () {
return Math.min(this.maxDelay, (1 << (this.retries++)) * this.baseDelay);
};
ExponentialReconnectionPolicy.prototype.reset = function () {
this.retries = 0;
};
return ExponentialReconnectionPolicy;
}());
export { ExponentialReconnectionPolicy };
//# sourceMappingURL=reconnection.js.map