Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fresh/tests/deps.ts>retry

The next-gen web framework.
Extremely Popular
Go to Latest
function retry
import { retry } from "https://deno.land/x/fresh@1.2.0/tests/deps.ts";

Creates a retry promise which resolves to the value of the input using exponential backoff. If the input promise throws, it will be retried maxAttempts number of times. It will retry the input every certain amount of milliseconds, starting at minTimeout and multiplying by the multiplier until it reaches the maxTimeout

Examples

Example 1

import { retry } from "https://deno.land/std@0.224.0/async/mod.ts";
const req = async () => {
 // some function that throws sometimes
};

// Below resolves to the first non-error result of `req`
const retryPromise = await retry(req, {
 multiplier: 2,
 maxTimeout: 60000,
 maxAttempts: 5,
 minTimeout: 100,
});

Parameters

fn: (() => Promise<T>) | (() => T)
optional
opts: RetryOptions