Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Retrying made simple, easy and async

License

NotificationsYou must be signed in to change notification settings

vercel/async-retry

Repository files navigation

Retrying made simple, easy, and async.

Usage

// Packagesconstretry=require('async-retry');constfetch=require('node-fetch');awaitretry(async(bail)=>{// if anything throws, we retryconstres=awaitfetch('https://google.com');if(403===res.status){// don't retry upon 403bail(newError('Unauthorized'));return;}constdata=awaitres.text();returndata.substr(0,500);},{retries:5,});

API

retry(retrier :Function,opts :Object)=>Promise
  • The supplied function can beasync or not. In other words, it can be a function that returns aPromise or a value.
  • The supplied function receives two parameters
    1. AFunction you can invoke to abort the retrying (bail)
    2. ANumber identifying the attempt. The absolute first attempt (before any retries) is1.
  • Theopts are passed tonode-retry. Readits docs
    • retries: The maximum amount of times to retry the operation. Default is10.
    • factor: The exponential factor to use. Default is2.
    • minTimeout: The number of milliseconds before starting the first retry. Default is1000.
    • maxTimeout: The maximum number of milliseconds between two retries. Default isInfinity.
    • randomize: Randomizes the timeouts by multiplying with a factor between1 to2. Default istrue.
    • onRetry: an optionalFunction that is invoked after a new retry is performed. It's passed theError that triggered it as a parameter.

Authors

About

Retrying made simple, easy and async

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors11


[8]ページ先頭

©2009-2025 Movatter.jp