npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@creejs/commons-retrier

v2.1.23

Published

Common Utils About Task Retrying

Readme

@creejs/commons-retrier

Commons-retrier Library provides a Retrier to:

  • Retry a task until it matches what you want

  • Options:

    • Times

      The max retires, how many times can we try?

    • Intervals

      After a retrying, what delay should we wait for?

      • Minimum Interval
      • Maximum Interval
      • Change Policy
        • Fixed Interval Policy
        • Fixed Increase Policy
        • Factor Increase Policy
        • Shuttle Policy
        • Exponential Backoff with Jitter
        • Fixed Backoff with Jitter
        • Linear Backoff with Jitter
    • Timeout

      After the "timeout", whole retries will fail with last error

    • TaskTimeout

      Timeout of one Task execution

And it supports two types of usage:

  1. retry(task)

    Run the task at intervals, until the task succeeds.

  2. always(task)

    Always run the task again and again, despit it fails or succeeds, until reaching the maxRetries, or total timeout

Install

npm intall @creejs/commons-retrier

Usage

  1. retry(task)

       const { Retrier } = require('@creejs/commons-retrier')
       
    // Chainable API to create and initialize Retrier
    const retrier = Retrier.infinite() // no retry limit
      .min(100) // min interval, 100ms
      .max(300) // max interval, 300ms
      .fixedIncrease(20) // each call, increase interval by 20ms
       
    // Task function to be retried
    const task = (retries, latency) => {
      if (retries <= 3) { // failed 3 times
        throw new Error('Task failed') // fails, if throw error, or reject promise
      }
      return 'success' // succeed at 4th try
    }
    // will end retries when first successfully call happens
    (async () => {
      try {
        const rtnVal = await retrier.task(task).start()
        console.log(rtnVal)
        // --> success
      } catch (err) {
        console.log(err)
      }
    })()
  2. always(task)

          
    const { Retrier } = require('@creejs/commons-retrier')
       
    // Chainable API to create and initialize Retrier
    const retrier = Retrier.times(4) // max retry 4 times
      .min(100) // min interval, 100ms
      .max(300) // max interval, 300ms
      .fixedIncrease(20) // each call, increase interval by 20ms
      .onSuccess((taskResult, retries, latency) => {
        console.log(taskResult)
      })
      .onFailure((err, retries, latency) => {
        console.error(err.message)
      })
      .onMaxRetries((nextRetries, maxRetries) => {
        console.error(`Max retries reached, ${nextRetries} > maxRetries ${maxRetries}`)
      })
       
    // Task function to be retried
    const task = (retries, latency) => {
      // succeed at 1, 2 try
      if (retries <= 2) {
        return `Latency ${latency}ms, Task succeeded at ${retries} try`
      }
      // fails at 3, 4 try, if throw error, or reject promise
      throw new Error(`Latency ${latency}ms, Task failed at ${retries} try`)
    }
       
    // will end retries when reach max retries
    (async () => {
      try {
        await retrier.always(task).start()
       
        console.log('Finished All Retries')
        // --> Latency 0ms, Task succeeded at 1 try
        // --> 105ms, Task succeeded at 2 try
        // --> Latency 228ms, Task failed at 3 try
        // --> Latency 370ms, Task failed at 4 try
        // --> Max retries reached, 5 > maxRetries 4
        // --> Finished All Retries
      } catch (err) {
        console.log(err)
      }
    })()