From 91b5fed818dc97805a63f6d630303ffe25daf021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Ku=C5=BCy=C5=84ski?= Date: Sat, 15 Apr 2017 07:13:55 +0200 Subject: [PATCH 1/2] Typescript definition file --- .gitignore | 1 + index.d.ts | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 66 +++++++++++++++++++++------------------ 3 files changed, 124 insertions(+), 30 deletions(-) create mode 100644 index.d.ts diff --git a/.gitignore b/.gitignore index c2658d7..a5199f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +.idea \ No newline at end of file diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..b774eb9 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,87 @@ +import {EventEmitter} from "events"; + +export interface BackoffStrategyOptions { + initialDelay?: number; + maxDelay?: number; + randomisationFactor?: number +} + +abstract class BackoffStrategy { + constructor(options?: BackoffStrategyOptions) + + getMaxDelay(): number; + + getInitialDelay(): number; + + next(); + + reset(); +} + +export class FibonacciStrategy extends BackoffStrategy { + +} + +export interface ExponentialStrategyOptions extends BackoffStrategyOptions { + factor?: number +} + +export class ExponentialStrategy extends BackoffStrategy { + constructor(options?: ExponentialStrategyOptions); + + public static DEFAULT_FACTOR: number; +} + +export class Backoff extends EventEmitter { + constructor(backoffStrategy: BackoffStrategy); + + failAfter(maxNumberOfRetry: number); + + backoff(err?: Error); + + reset(); +} + + +export class FunctionCall extends EventEmitter { + + constructor(fn: Function, args: any[], callback: Function); + + isPending(): boolean; + + isRunning(): boolean; + + isCompleted(): boolean; + + isAborted(): boolean; + + setStrategy(strategy: BackoffStrategy): this; + + retryIf(retryPredicate: (err: Error) => boolean): this; + + getLastResult(): any; + + getNumRetries(): number; + + failAfter(maxNumberOfRetry: number): this; + + abort(); + + start(backoffFactory?: (strategy: BackoffStrategy) => Backoff); +} + +export function fibonacci(options?: BackoffStrategyOptions): Backoff; + +export function exponential(options?: ExponentialStrategyOptions): Backoff; + +// Have to be done that way until this gets solved https://github.com/Microsoft/TypeScript/issues/1360 +export function call(fn: Function, arg1: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, arg3: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, arg3: any, arg4: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, arg9: any, callback: Function): FunctionCall; +export function call(fn: Function, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, arg9: any, arg10: any, callback: Function): FunctionCall; \ No newline at end of file diff --git a/package.json b/package.json index b6d6cb6..aa4bb96 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,38 @@ { - "name": "backoff", - "description": "Fibonacci and exponential backoffs.", - "version": "2.5.0", - "license": "MIT", - "author": "Mathieu Turcotte ", - "keywords": ["backoff", "retry", "fibonacci", "exponential"], - "repository": { - "type": "git", - "url": "https://github.com/MathieuTurcotte/node-backoff.git" - }, - "dependencies": { - "precond": "0.2" - }, - "devDependencies": { - "sinon": "1.10", - "nodeunit": "0.9" - }, - "scripts": { - "docco" : "docco lib/*.js lib/strategy/* index.js", - "pretest": "jshint lib/ tests/ examples/ index.js", - "test": "node_modules/nodeunit/bin/nodeunit tests/" - }, - "engines": { - "node": ">= 0.6" - }, - "files": [ - "index.js", - "lib", - "tests" - ] + "name": "backoff", + "description": "Fibonacci and exponential backoffs.", + "version": "2.5.0", + "license": "MIT", + "author": "Mathieu Turcotte ", + "keywords": [ + "backoff", + "retry", + "fibonacci", + "exponential" + ], + "repository": { + "type": "git", + "url": "https://github.com/MathieuTurcotte/node-backoff.git" + }, + "dependencies": { + "precond": "0.2" + }, + "devDependencies": { + "@types/node": "^7.0.12", + "nodeunit": "0.9", + "sinon": "1.10" + }, + "scripts": { + "docco": "docco lib/*.js lib/strategy/* index.js", + "pretest": "jshint lib/ tests/ examples/ index.js", + "test": "node_modules/nodeunit/bin/nodeunit tests/" + }, + "engines": { + "node": ">= 0.6" + }, + "files": [ + "index.js", + "lib", + "tests" + ] } From 1056752b65a9c3978ea2e50273c4ece8956eb346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Ku=C5=BCy=C5=84ski?= Date: Sat, 15 Apr 2017 20:25:46 +0200 Subject: [PATCH 2/2] revert style changed to package.json --- package.json | 67 ++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index aa4bb96..fb73119 100644 --- a/package.json +++ b/package.json @@ -1,38 +1,33 @@ { - "name": "backoff", - "description": "Fibonacci and exponential backoffs.", - "version": "2.5.0", - "license": "MIT", - "author": "Mathieu Turcotte ", - "keywords": [ - "backoff", - "retry", - "fibonacci", - "exponential" - ], - "repository": { - "type": "git", - "url": "https://github.com/MathieuTurcotte/node-backoff.git" - }, - "dependencies": { - "precond": "0.2" - }, - "devDependencies": { - "@types/node": "^7.0.12", - "nodeunit": "0.9", - "sinon": "1.10" - }, - "scripts": { - "docco": "docco lib/*.js lib/strategy/* index.js", - "pretest": "jshint lib/ tests/ examples/ index.js", - "test": "node_modules/nodeunit/bin/nodeunit tests/" - }, - "engines": { - "node": ">= 0.6" - }, - "files": [ - "index.js", - "lib", - "tests" - ] + "name": "backoff", + "description": "Fibonacci and exponential backoffs.", + "version": "2.5.0", + "license": "MIT", + "author": "Mathieu Turcotte ", + "keywords": ["backoff", "retry", "fibonacci", "exponential"], + "repository": { + "type": "git", + "url": "https://github.com/MathieuTurcotte/node-backoff.git" + }, + "dependencies": { + "precond": "0.2" + }, + "devDependencies": { + "sinon": "1.10", + "nodeunit": "0.9", + "@types/node": "^7.0.12" + }, + "scripts": { + "docco" : "docco lib/*.js lib/strategy/* index.js", + "pretest": "jshint lib/ tests/ examples/ index.js", + "test": "node_modules/nodeunit/bin/nodeunit tests/" + }, + "engines": { + "node": ">= 0.6" + }, + "files": [ + "index.js", + "lib", + "tests" + ] }