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

retry-toolkit

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retry-toolkit

The `retry-toolkit` is designed to address a common issue in software development: dealing with transient failures or temporary issues when performing operations such as network requests, API calls, or database queries. Here's a detailed explanation of th

latest
npmnpm
Version
1.0.3
Version published
Maintainers
0
Created
Source

Retry Toolkit

The retry-toolkit is designed to address a common issue in software development: dealing with transient failures or temporary issues when performing operations such as network requests, API calls, or database queries. Here's a detailed explanation of the problem it solves:

Handling Transient Failures: These are temporary issues that can occur intermittently and may be resolved with a subsequent retry. For example, network glitches, temporary server downtime, or rate limits imposed by APIs.

Manual Retry Logic: Developers often need to implement custom retry logic to handle these failures. This can involve writing repetitive and error-prone code to retry failed operations a specific number of times with a delay between attempts.

Configuration Complexity: Implementing retry logic requires configuring parameters like the number of retries, delay between attempts, and handling different types of errors. Doing this manually can be cumbersome and inconsistent across different parts of an application.

Installation

npm install retry-toolkit

Usage

const retry = require('retry-toolkit');

// Define a function that may fail
const fetchData = async () => {
  console.log('Attempting to fetch data...');
  throw new Error('Simulated fetch failure');
};

// Use retry-package with exponential backoff
retry(fetchData, {
  retries: 5,             // Retry up to 5 times
  delay: 1000,            // Initial delay of 1 second
  backoff: 'exponential', // Exponential backoff
  retryOnError: (error) => error.message !== 'Non-retryable error', // Retry only on certain errors
  timeout: 10000,         // Timeout for each attempt set to 10 seconds
  onRetry: (attemptNumber, error) => {
    console.log(`Retry attempt ${attemptNumber} failed: ${error.message}`);
  },
  onFailure: (error) => {
    console.error('Final failure after retries:', error.message);
  }
}).then(data => {
  console.log('Data fetched successfully:', data);
}).catch(error => {
  console.error('Error:', error.message);
});

FAQs

Package last updated on 28 Aug 2024

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