New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

better-retry

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-retry

Basically a rewrite of p-retry

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

better-retry

A better way to handle retries on promise-returning/async functions, with ESM, CJS, AMD and UMD support.
It is basically p-retry rewritten in Typescript with Commonjs support.

🎉 Features

  • Exponential backoff
  • Custom retry strategy support
  • Timeout settings

📝 To-do

  • Add custom abort signal handlers

⚙ Install

# npm
npm i better-retry

# yarn
yarn add better-retry

📖 Docs

You can read docs here.

🔍 Usage

import { betterRetry, FailedAttemptError } from 'better-retry';

const run = async (attempt: number) => {
  if (attempt > 5) return 'Success!';

  throw new Error('Failed');
};

const onError = (error: FailedAttemptError) => {
  console.log(`Attempt ${error.attempt} failed. There are ${error.retriesLeft} retries left.`);
}

console.log(await betterRetry(run), { retries: 5, onFailedAttempt: onError }); // Success!

️❤️ Contributing

Every contribution is really welcome!

If you feel that something can be improved or should be fixed, feel free to open an issue with the feature or the bug found.

If you want to fork and open a pull request (adding features or fixes), feel free to do it. Remember only to use the dev branch as a base.

Read the contributing guidelines

📃 Licence

Read the licence

Keywords

FAQs

Package last updated on 12 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc