1.3.3 • Published 4 years ago

async-retry v1.3.3

Weekly downloads
2,288,856
License
MIT
Repository
github
Last release
4 years ago

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

@google-cloud/storageapollo-server-coregcs-resumable-uploadzikix-core@dxatscale/sfpowerscripts@npmsoluto/fetch-enhancerscommit-cz-fix@amygrooove1/smart-order-router-horiza-forkeasy-select-rncommon-platformreact-native-bluetooth2sygna-bridge-api@lambot/exchangeaerolito-nextcfn-custom-response@getholo/api-client@nuragic/apollo-engine-reportingtask-service-containervtex3work-scriptsvoid-maill7mpairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-moduleultimate-backenddelivery-parametersbitcasino-v3deneme323112maitsa-service@ntt_app/react-native-custom-notification@faros-ai/cli@radar/chain-watchers-ethereumreact-native-covid-sdk@tuplo/fletchpoblouin-homebridge-zigbee-ntcreate-tactech-app@trieb.work/zoho-inventory-tsreact-native-printer-brotherstsumiki-reddit.jsreact-native-shekhar-bridge-testtaskfire-cli@oiti/documentoscopy-react-nativefirestore-servicesquoc-testswash-smart-router@ersanyakit/smart-order-router@tigrisdata/create-tigris-appthing-it-servermy_smart_orderrouterluminos-ui-coresfpowerkit@everything-registry/sub-chunk-1175pw-testjawwy-sdkjawwy_gamification_release@arthswap/smart-order-routeropenflow-clinode-backpack.tfreact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkg@cryptoalgebra/router@cryptoalgebra/router-2react-native-jawwy_samplegriffin-ui-librarytakeshape-clitailwindtest-dex-smart-order-routertest-jugglertest-library-123test-haptik-libweiweb3wolkenkit-eventstorewillitweb3sdkioweb3sdksweixiao-code-pluginwell-comeetwereleasewristband-node-m2mwzt-plugin-release-itwifi_configuration_packagestoryblok-management-api-wrappersprd-design-uploadsperax-smart-order-routerstorybook-chromastorybook-chromatictest-result-reporter-improvedtest-results-reportertest-zeo-collecttestbeatstestbluedex-smart-order-routertestsolar-oss-jestswap-router-sdktgit-apivortex-ext-httpvtex
1.3.3

4 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.3.0

8 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago