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

Promise Retried

Retry a promise-returning or async function. Deno port of sindresorhus’s p-retry for node

build status language code size issues license version

View on deno.land




Abstraction for exponential and custom retry strategies for failed operations

Usage

import pRetried, {
    AbortError,
} from "https://deno.land/x/p_retried@1.0.6/mod.ts"

async function run() {
    const response = await fetch("https://sindresorhus.com/unicorn")

    // Abort retrying if the resource doesn't exist
    if (response.status === 404) {
        throw new AbortError(response.statusText)
    }

    return response.blob()
}

console.log(await pRetried(run, { retries: 5 }))

API

See https://doc.deno.land/https/deno.land/x/p_retried@1.0.6/lib/mod.ts

Tip

You can pass arguments to the function being retried by wrapping it in an inline arrow function:

import pRetried from "https://deno.land/x/p_retried@1.0.6/mod.ts"

const run = async emoji => {
    // …
}

// Without arguments
await pRetried(run, {
    retries: 5,
})

// With arguments
await pRetried(() => run("🦄"), {
    retries: 5,
})

Supporters

  • HUGE thanks to @sindresorhus – this repository is mostly his code, modified to work with Deno

Stargazers repo roster for @KhushrajRathod/pRetried

Forkers repo roster for @KhushrajRathod/pRetried

License