Nestable Processes Mutate

    async-retry
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/async-retry package

    1.3.3 • Public • Published

    async-retry

    Retrying made simple, easy, and async.

    Usage

    // Packages
    const retry = require('async-retry');
    const fetch = require('node-fetch');
    
    await retry(
      async (bail) => {
        // if anything throws, we retry
        const res = await fetch('https://google.com');
    
        if (403 === res.status) {
          // don't retry upon 403
          bail(new Error('Unauthorized'));
          return;
        }
    
        const data = await res.text();
        return data.substr(0, 500);
      },
      {
        retries: 5,
      }
    );

    API

    retry(retrier : Function, opts : Object) => Promise
    • The supplied function can be async or not. In other words, it can be a function that returns a Promise or a value.
    • The supplied function receives two parameters
      1. A Function you can invoke to abort the retrying (bail)
      2. A Number identifying the attempt. The absolute first attempt (before any retries) is 1.
    • The opts are passed to node-retry. Read its docs
      • retries: The maximum amount of times to retry the operation. Default is 10.
      • factor: The exponential factor to use. Default is 2.
      • minTimeout: The number of milliseconds before starting the first retry. Default is 1000.
      • maxTimeout: The maximum number of milliseconds between two retries. Default is Infinity.
      • randomize: Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is true.
      • onRetry: an optional Function that is invoked after a new retry is performed. It's passed the Error that triggered it as a parameter.

    Authors

    Keywords

    none

    Install

    npm i async-retry

    DownloadsWeekly Downloads

    4,369,156

    Version

    1.3.3

    License

    MIT

    Unpacked Size

    5.21 kB

    Total Files

    4

    Last publish

    Collaborators

    • javierbyte
    • kayernyc
    • janory
    • goncy
    • codyogden
    • feedthejim
    • tilly3g
    • wits
    • feugy
    • gbibeaulaviolette
    • megbird
    • dizzyup
    • vin-e
    • edgarcerecerezv
    • livcarman
    • segunadebayo
    • pm24601
    • sambecker
    • craigandrews
    • mjakobis
    • kale-stew
    • chloe.tedder
    • pbto
    • daniel.campbell
    • arian-vercel
    • nuta
    • almonk
    • samselikoff
    • dcartertwo
    • baruchadi
    • ejc
    • aaorris
    • doque
    • ryanto
    • nathanhammond
    • snokohn
    • johnphamous
    • tknickman
    • agadzik
    • thomcrowe
    • emeraldsanto
    • ecklf
    • timeyoutakeit
    • cramforce
    • balazs4
    • casey.gowrie
    • samuel.foster
    • swarnavasengupta
    • lydiahallie
    • ethan_arrowood
    • kwonoj
    • kakadiadarpan
    • amanhimself_
    • endangeredmassa
    • nick.tracey
    • reconbot
    • schlez
    • crowterli
    • gsoltis
    • epallerols
    • domysee
    • nwienert
    • arbw
    • stephdietz
    • gudmundur
    • marcgreenstock
    • vvo
    • falcoagustin
    • nabsul
    • bmealey
    • maedahbatool
    • brethudson
    • matt.straka
    • jasongullickson
    • f3d0r
    • gaspar09
    • jtaylor0196
    • pieparker
    • kelly
    • dferber90
    • healeycodes
    • broph123
    • codybrouwers
    • gdborton
    • jeffreyarneson
    • ebb-tide
    • msimulcik
    • domeccleston
    • nutlope
    • hungrybearstudio
    • codetaromiura
    • gkaragkiaouris
    • geovanisouza92
    • dglsparsons
    • lostinpatterns
    • vercel-release-bot
    • southpolesteve
    • matheuss
    • igorklopov
    • nkzawa
    • tootallnate
    • rauchg
    • timneutkens
    • javivelasco
    • iamevilrabbit
    • kdy1
    • quietshu
    • styfle
    • zeit-bot
    • lucleray
    • mglagola
    • andybitz
    • paulogdm
    • anatrajkovska
    • timer
    • arzafran
    • ijjk
    • lfades
    • msweeneydev
    • williamli
    • ragojose
    • guybedford
    • skllcrn
    • janicklas-ralph
    • atcastle
    • spanicker
    • housseindjirdeh
    • gmonaco
    • kikobeats
    • prateekbh
    • jkrems
    • jaredpalmer
    • gielcobben
    • chibicode
    • nazarenooviedo
    • samsisle
    • okbel
    • hankvercel
    • leerobinson
    • elsigh
    • julianbenegas
    • rizbizkits
    • sokra
    • cl3arglass
    • chriswdmr
    • ernestd
    • ismaelrumzan
    • jhoch
    • mitchellwright
    • mrmckeb
    • kuvos
    • creationix
    • huozhi
    • cmvnk
    • ktcarter
    • padmaia
    • delba
    • catsaremlg
    • steventey
    • gsandhu
    • dbredvick