Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions dread.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
type JitterOptions = {
base?: number = 100;
factor?: number = 2;
limit?: number = 1000;
jitter?: JitterType = JitterType.FULL;
};

export enum JitterType {
NONE = "NONE",
FULL = "FULL",
HALF = "HALF",
}

export type DreadConfig = {
timeout?: number = undefined;
attempts: number = 10;
backoff?: number;
condition?: boolean | ((err: any) => boolean);
};

export type Attempt = {
attempt: number;
number: number;
cancel: (reason: string | any = "Attempt cancelled") => void;
timeout: (duration: number) => void;
};

type DreadFunction = {
(
task: (attempt: Attempt) => void | any | Promise<any>,
config?: DreadConfig
): void;
(config?: DreadConfig): DreadFunction;
prop: (key: string) => boolean;
is: (classInstance: any) => boolean;
code: (str: string) => boolean;
always: () => true;
exp: (options?: JitterOptions) => (numb: number) => number;
};

declare const dread: DreadFunction;

export default dread;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "dread",
"version": "2.3.0",
"version": "2.3.1",
"description": "yet another retry library",
"main": "dread.js",
"types": "dread.d.ts",
"scripts": {
"test": "nyc --all ava test/spec.js",
"perf": "ava test/perf.js",
Expand Down