Socket
Socket
Sign inDemoInstall

tryer

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

tryer

Because everyone loves a tryer! Conditional and repeated task invocation for node and browser.


Version published
Weekly downloads
3.6M
decreased by-5.1%
Maintainers
1
Weekly downloads
 
Created

What is tryer?

The 'tryer' npm package is a utility for handling retries of asynchronous operations. It allows you to specify retry logic, including the number of attempts, delay between attempts, and conditions for retrying.

What are tryer's main functionalities?

Basic Retry Logic

This feature allows you to retry an asynchronous function a specified number of times with a delay between attempts. The 'action' function is the operation to be retried, 'pass' determines if the operation was successful, and 'fail' handles the failure case.

const tryer = require('tryer');

tryer({
  action: function() {
    return someAsyncFunction();
  },
  pass: function(result) {
    return result.success;
  },
  fail: function(err) {
    console.error('Failed:', err);
  },
  attempts: 3,
  delay: 1000
});

Conditional Retry

This feature allows you to specify a condition under which the retry attempts should stop early. The 'until' function checks if a certain condition is met to stop retrying before reaching the maximum number of attempts.

const tryer = require('tryer');

tryer({
  action: function() {
    return someAsyncFunction();
  },
  pass: function(result) {
    return result.success;
  },
  fail: function(err) {
    console.error('Failed:', err);
  },
  until: function(result) {
    return result.shouldStop;
  },
  attempts: 5,
  delay: 500
});

Exponential Backoff

This feature allows you to implement exponential backoff for retry attempts. The 'delay' function calculates the delay based on the attempt number, increasing the delay exponentially with each retry.

const tryer = require('tryer');

tryer({
  action: function() {
    return someAsyncFunction();
  },
  pass: function(result) {
    return result.success;
  },
  fail: function(err) {
    console.error('Failed:', err);
  },
  attempts: 4,
  delay: function(attempt) {
    return Math.pow(2, attempt) * 100;
  }
});

Other packages similar to tryer

Keywords

FAQs

Package last updated on 24 Jun 2018

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