Skip to content

Commit

Permalink
change JitterTypes from enum to union (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
hudovisk committed Apr 3, 2020
1 parent f8aaeb8 commit 16f3f46
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/jitter/jitter.factory.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { IBackOffOptions, JitterTypes } from "../options";
import { IBackOffOptions } from "../options";
import { fullJitter } from "./full/full.jitter";
import { noJitter } from "./no/no.jitter";

export type Jitter = (delay: number) => number;

export function JitterFactory(options: IBackOffOptions): Jitter {
switch (options.jitter) {
case JitterTypes.Full:
case "full":
return fullJitter

case JitterTypes.None:
case "none":
default:
return noJitter
}
Expand Down
9 changes: 3 additions & 6 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
export enum JitterTypes {
None = "none",
Full = "full"
}
export type JitterType = "none" | "full";

export interface IBackOffOptions {
delayFirstAttempt: boolean;
jitter: JitterTypes;
jitter: JitterType;
maxDelay: number;
numOfAttempts: number;
retry: (e: any, attemptNumber: number) => boolean;
Expand All @@ -15,7 +12,7 @@ export interface IBackOffOptions {

const defaultOptions: IBackOffOptions = {
delayFirstAttempt: false,
jitter: JitterTypes.None,
jitter: "none",
maxDelay: Infinity,
numOfAttempts: 10,
retry: () => true,
Expand Down

0 comments on commit 16f3f46

Please sign in to comment.