Skip to content

Commit

Permalink
refactor: use already declared sleep function (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrel authored Dec 11, 2023
1 parent 68956e4 commit 9a0c236
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/entrypoints/retry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AnyFunction } from "../common";
import { sleep } from "./sleep";

type RetryParameters = {
maxRetries?: number;
Expand All @@ -12,10 +13,7 @@ type RetryParameters = {

type RetryReturnType<T extends AnyFunction> = Promise<ReturnType<T>>;

const sleep = async (time: number) =>
new Promise((resolve) => setTimeout(resolve, time));

const rejectsIn = (time: number) => new Promise((_, reject) => setTimeout(() => reject('Timeout limit reached'), time));
const rejectsIn = (time: number) => sleep(time).then(()=>Promise.reject("Timeout limit reached"));

export async function retry<T extends AnyFunction>(
fn: T,
Expand Down

0 comments on commit 9a0c236

Please sign in to comment.