UNPKG

920 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Host = void 0;
4const urlModule = require("url");
5class Host {
6 /**
7 * Creates a new Host instance.
8 * @param url
9 * @param backoff
10 */
11 constructor(url, backoff, options) {
12 this.backoff = backoff;
13 this.options = options;
14 this.url = urlModule.parse(url);
15 }
16 /**
17 * Marks a failure on the host and returns the length of time it
18 * should be removed from the pool
19 * @return removal time in milliseconds
20 */
21 fail() {
22 const value = this.backoff.getDelay();
23 this.backoff = this.backoff.next();
24 return value;
25 }
26 /**
27 * Should be called when a successful operation is run against the host.
28 * It resets the host's backoff strategy.
29 */
30 success() {
31 this.backoff = this.backoff.reset();
32 }
33}
34exports.Host = Host;