New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

error-retry

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

error-retry

Error retries for async functions or functions that return a promise

latest
Source
npmnpm
Version
0.0.2
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

error-retry

Easy error handling for async functions or any function that returns a promise. Errors are retried with an exponential backoff delay between each attempt.

Install

$ npm install error-retry

Usage

var { retry, setMaxRetries } = require('error-retry');

// Example function that just throws errors until called four times.
var exampleCount = 0;
async function example(param1, param2) {
   ++exampleCount
   console.log(`example() called param1: ${param1} param2: ${param2} try: ${exampleCount}`)
   if (exampleCount < 4) {
       throw Error('example failure')
   }
   return 'example success!'
}

(async function() {
    try {
        // Call example() with error retry handling
        var result =  await retry(() => example('abc', 123))
        console.log(`result = ${result}`)
    }
    catch (ex) {
        console.log(`ex = ${ex}`)
    }
}())

Max Retries

The default number of retries is 3. To modify this value call:

setMaxRetries(5)

License

MIT license; see LICENSE.

Keywords

retry

FAQs

Package last updated on 17 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts