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 🙏

© 2024 – Pkg Stats / Ryan Hefner

robust-promise

v1.0.8

Published

Retry promise. Easy to use, retryable promise. Pass it a promise, get a robust-promise!

Downloads

11

Readme

CircleCI

  • Production Ready
  • Takes your promise and returns a robust-promise
  • retries execution several times for extra reliability
  • Simple and easy to use
  • Highly configurable and flexible
  • It's magic!

Simple Usage

First of all, import the library:

const robustPromise = require('robust-promise')

Let's say for example, you want to send an email. You already have a sendEmail function that returns a promise.

robustPromise(sendEmail)

Wow, that was painless!

Note that sendMail is used here as an example only. You can use this for anything!

You can then treat your robust promise function, just like you would of treated your original function, e.g.

robustPromise(sendEmail)
  .then(console.log('so robust'))
  .catch(console.log('wow'))

By default, robust-promise will try to send your email three times before rejecting. The delay between each attempt will exponentially increase according to the attempot number.

Note: robust-promise actually expects a function that returns a promise, not an actual promise. So, if you need to pass options to your function, you can wrap it in a function like so:

robustPromise(() => sendEmail(options))

Advanced Usage

Let's say that you want to configure the number of retries to 6. That's easy:

robustPromise(sendEmail, 6)

Next-Level Usage

Let's say that you want to configure the number of retries to 20, and the delay to half a second. Here you go:

robustPromise(sendEmail, 20, 0.5)

HARDCORE USAGE

Let's say that you are a hardcore mofo, you want to configure the number of retries to 10, with a ten sencond delay. But you are also so hard, that you don't want the delay to exponentially increase. We have you covered:

const cfg = {
  retries: 10,
  delay: 10,
  exp: false
}

robustPromise(sendEmail, cfg.retries, cfg.delay, cfg.exp)

Contributing

Contributions are more than welcome! To contribute

  • Opening a pull request
  • Reporting an issue

Tests

To run the unit tests:

npm test