1.3.3 • Published 3 years ago

async-retry v1.3.3

Weekly downloads
2,288,856
License
MIT
Repository
github
Last release
3 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

gcs-resumable-upload@google-cloud/storageapollo-server-corezikix-core@dxatscale/sfpowerscripts@npmsoluto/fetch-enhancers@graphql-hive/clientcommit-cz-fix@amygrooove1/smart-order-router-horiza-fork@taqueria/plugin-flextesaapify-clienteasy-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-corethirdwebsfpowerkit@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_sample@unibtc/release-it@zalastax/nolb-async-r@zoralabs/uniswap-smart-order-router@susytech/electron@vtex/cli-plugin-test@valifysolutions/react-native-vidvliveness@victorcolombo/tjwsbfnhsn@vidocsecurity/vidoc-importer@uniswapfoundation/smart-order-router@uniswap/smart-order-router@yplabs-ltd/react-native-detector@yumyumswap/smart-order-router@unsync/ai-gateway@uttacoin/metaplex.js@warpgatex/warp-smart-order-router@waterfor9/smart-order-router-old@waterfor9/smart-order-router@vercel/fetch-retry@vercel/client@vercel/blob@zhumi/lite_rpa@u2dv/marketplace_common@audius/sdk@aurora-is-near/backstage-plugin-blockchainradar-backend@corelmax/react-native-my2c2p-sdk@damruravihara/react-native-testing-package@balena/jellyfish-plugin-hubot@cytoswap/smart-order-router@baotg/core
1.3.3

3 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.4

6 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.3.0

7 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago