Skip to content

Commit

Permalink
Merge 842c885 into 54c6ddf
Browse files Browse the repository at this point in the history
  • Loading branch information
bencevans committed May 22, 2019
2 parents 54c6ddf + 842c885 commit bc2dafa
Show file tree
Hide file tree
Showing 29 changed files with 9,839 additions and 9,616 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ language: node_js
node_js:
- "8"
- "10"
- "12"
services:
- docker
before_install:
Expand Down
11,589 changes: 5,900 additions & 5,689 deletions package-lock.json

Large diffs are not rendered by default.

64 changes: 39 additions & 25 deletions package.json
Expand Up @@ -12,13 +12,13 @@
"fmt": "prettier --single-quote --trailing-comma all --print-width 100 --write \"{src,test,examples}/**/*.ts\" && npm run test:lint -- --fix",
"test": "npm-run-all --parallel test:lint test:unit test:integrate",
"test:browser": "karma start test/karma.conf.js",
"test:cover": "npm run build:dist && istanbul cover _mocha -- lib/test/unit/*.test.js && opn coverage/lcov-report/index.html",
"test:integrate": "mocha --compilers ts:ts-node/register --timeout 20000 test/integrate/*.test.ts",
"test:lint": "tslint --project tsconfig.json '{src,test}/**/*.ts'",
"test:cover": "npm run build:dist && istanbul cover _mocha -- lib/test/unit/*.test.js && open-cli coverage/lcov-report/index.html",
"test:integrate": "mocha --require ts-node/register --timeout 20000 test/integrate/*.test.ts",
"test:lint": "eslint '{src,test}/**/*.ts'",
"test:sauce": "SAUCE=1 karma start test/karma.conf.js",
"test:travis": "npm-run-all clean test:lint test:sauce test:integrate build:dist && istanbul cover _mocha --report lcovonly -- lib/test/unit/*.test.js",
"test:unit": "mocha --compilers ts:ts-node/register test/unit/*.test.ts",
"test:watch": "mocha -R min --watch --compilers ts:ts-node/register test/unit/*.test.ts"
"test:unit": "mocha --require ts-node/register test/unit/*.test.ts",
"test:watch": "mocha -R min --watch --require ts-node/register test/unit/*.test.ts"
},
"repository": {
"type": "git",
Expand All @@ -40,36 +40,50 @@
"license": "MIT",
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^2.2.32",
"@types/node": "^9.4.5",
"@types/sinon": "^4.1.3",
"@types/sinon-chai": "^2.7.27",
"awesome-typescript-loader": "^3.0.8",
"@types/freeport": "^1.0.21",
"@types/mocha": "^5.2.6",
"@types/node": "^12.0.2",
"@types/sinon": "^7.0.11",
"@types/sinon-chai": "^3.2.2",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"awesome-typescript-loader": "^5.2.1",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"esdoc": "^1.0.4",
"coveralls": "^3.0.3",
"esdoc": "^1.1.0",
"eslint": "^5.16.0",
"eslint-config-xo": "^0.26.0",
"eslint-config-xo-typescript": "^0.12.0",
"freeport": "^1.0.5",
"istanbul": "^0.4.3",
"json-loader": "^0.5.4",
"karma": "^2.0.0",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.0.0",
"karma-mocha": "^1.2.0",
"karma-mocha-reporter": "^2.2.0",
"karma-sauce-launcher": "^1.0.0",
"karma-sauce-launcher": "^2.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.2",
"lodash": "^4.16.2",
"mocha": "^5.0.0",
"karma-webpack": "^3.0.5",
"lodash": "^4.17.11",
"mocha": "^6.1.4",
"node-fetch": "^2.0.0",
"npm-run-all": "^4.0.2",
"opn-cli": "^3.1.0",
"open-cli": "^5.0.0",
"prettier": "^1.4.4",
"sinon": "^4.3.0",
"sinon-chai": "^2.8.0",
"sinon": "^7.3.2",
"sinon-chai": "^3.3.0",
"stream-http": "github:node-influx/stream-http",
"ts-node": "^4.1.0",
"tslint": "^5.9.1",
"tslint-microsoft-contrib": "^5.0.2",
"typescript": "^2.7.1",
"webpack": "^3.11.0"
"ts-node": "^6.2.0",
"typescript": "^3.4.5",
"webpack": "^4.31.0"
},
"eslintConfig": {
"extends": [
"xo",
"xo-typescript"
],
"rules": {
"@typescript-eslint/interface-name-prefix": false,
"@typescript-eslint/camelcase": "warn"
}
}
}
14 changes: 7 additions & 7 deletions src/backoff/backoff.ts
@@ -1,17 +1,17 @@
export interface IBackoffStrategy {
/**
* getDelay returns the amount of delay of the current backoff.
/**
* GetDelay returns the amount of delay of the current backoff.
*/
getDelay(): number;
getDelay(): number;

/**
/**
* Next is called when a failure occurs on a host to
* return the next backoff amount.
*/
next(): IBackoffStrategy;
next(): IBackoffStrategy;

/**
/**
* Returns a strategy with a reset backoff counter.
*/
reset(): IBackoffStrategy;
reset(): IBackoffStrategy;
}
66 changes: 31 additions & 35 deletions src/backoff/exponential.ts
@@ -1,70 +1,66 @@
import { IBackoffStrategy } from './backoff';
import {IBackoffStrategy} from './backoff';

/**
* IExponentialOptions are passed into the ExponentialBackoff constructor. The
* backoff equation is, in general, min(max, initial ^ n), where `n` is
* an incremented backoff factor. The result of the equation is a delay
* given in milliseconds.
*
* @typedef {Object} IExponentialOptions
* @property {Number} initial The initial delay passed to the equation.
* @property {Number} random Random factor to subtract from the `n` count.
* @property {Number} max Max is the maximum value of the delay.
*/
export interface IExponentialOptions {
/**
/**
* The initial delay passed to the equation.
*/
initial: number;
initial: number;

/**
/**
* Random factor to subtract from the `n` count.
*/
random: number;
random: number;

/**
* max is the maximum value of the delay.
/**
* Max is the maximum value of the delay.
*/
max: number;
max: number;
}

/**
* @class
* @implements {IBackoffStrategy}
* Exponential Backoff
* @see https://en.wikipedia.org/wiki/Exponential_backoff
*/
export class ExponentialBackoff implements IBackoffStrategy {
private counter: number;
private _counter: number;

/**
/**
* Creates a new exponential backoff strategy.
* @see https://en.wikipedia.org/wiki/Exponential_backoff
* @param {IExponentialOptions} options
* @param options
*/
constructor(protected options: IExponentialOptions) {
this.counter = 0;
}
constructor(protected options: IExponentialOptions) {
this._counter = 0;
}

/**
/**
* @inheritDoc
*/
public getDelay(): number {
const count = this.counter - Math.round(Math.random() * this.options.random); // tslint:disable-line
return Math.min(this.options.max, this.options.initial * Math.pow(2, Math.max(count, 0)));
}
public getDelay(): number {
const count = this._counter - Math.round(Math.random() * this.options.random); // Tslint:disable-line
return Math.min(this.options.max, this.options.initial * Math.pow(2, Math.max(count, 0)));
}

/**
/**
* @inheritDoc
*/
public next(): IBackoffStrategy {
const next = new ExponentialBackoff(this.options);
next.counter = this.counter + 1;
return next;
}
public next(): IBackoffStrategy {
const next = new ExponentialBackoff(this.options);
next._counter = this._counter + 1;
return next;
}

/**
/**
* @inheritDoc
*/
public reset(): IBackoffStrategy {
return new ExponentialBackoff(this.options);
}
public reset(): IBackoffStrategy {
return new ExponentialBackoff(this.options);
}
}

0 comments on commit bc2dafa

Please sign in to comment.