🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

just-retry-it

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-retry-it

Retries with error handler

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

just-retry-it

A simple async/await wrapper around promise-retry and retry.

Why?

  • Simplify the interface. You don't need to write the try-catch-retry part yourself.
  • Accept an optional error handler function that will be called after each failed attempt.

Kudos to promise-retry and retry authors 🙏.

Installation

$ npm install just-retry-it

Usage

await retry(operation, options?)
  • operation: The operation to be executed and retried if the execution should fail.
  • options: The options object as it is desrcibed in the retry NPM package.
    • options also supports the errorHandler property (optional) to pass an error handler function, which will be called right after the operation if it throws. The handler receives the thrown error as the input.

Example

import retry from 'just-retry-it';

async function getMessage() {
    if (Math.random() > 0.5) {
        return "Hello World!";
    }

    throw new Error("boom");
}

async function run() {
    // Retry without the error handler.
    const msg1 = await retry(getMessage, { retries: 5 });
    
    async function errorHandler(error) {
        console.log("received an error", error);
    }
    
    // Retry with the error handler.
    const msg2 = await retry(getMessage, { retries: 5, errorHandler });
}

License

MIT

Keywords

retry

FAQs

Package last updated on 24 Jan 2023

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