Giter Club home page Giter Club logo

exponential-backoff's People

Contributors

dependabot[bot] avatar hudovisk avatar louis-bompart avatar raphinesse avatar samisayegh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

exponential-backoff's Issues

Retry Function based on API Response vs API Error

Hey ๐Ÿ‘‹

We have a use case where we need to dictate whether to retry based on the response from an API call, not the error from the call.

I want to perform a retry is response.data is equal to an empty object. E.G {}. The API won't "error" from this, the response will be a 200 and it has got some data back, the data is just an empty object.

Right now, the retry function only allows you to access the error and the number of attempts. In my use case that doesn't quite seem to fit the need ๐Ÿ˜ข

Maybe I am missing something in your docs (and I'm sorry if I am), I have done some trial and error locally on my machine, but I can't seem to access the response in the retry function.

Have you got an example of this working, if not, is it something you would think about incorporating?

Async `retry` function.

Are there plans to make the retry function an async one returning Promise<boolean>?
I need to do some async code execution in there (Deleting the currently stored access token if we are getting a not authenticated error).

Thanks for this amazing lib!

Best regards,
Yannick

Change method signature for usability

It's weird that the first argument is not just the function when all other arguments are optional

Move retry function to the second argument (backoff options) and make the first argument the function (preferred)

Or make the only argument an object where the only required key is the fn key (dislike this because the 'fn' key is not intuitive)

The delay with jitter can be equal to 0

in the fullJitter function, a random number is used to calculate the delay, which is multiplied by prevDelay*e^attemptNumber.
But Math.random() can return 0, and then the total delay before repeating the request will be 0.
Is this a bug, or ok?

image

Inverse exponential backoff

Is there any scope for adding functionality for inverse exponential backoff?
A simple DX would be to add a negative integer value to the timeMultiple , a minDelay optioion.

There are multiple uses case especially when we use polling APIs to get the result of an async task.
It doesn't make sense increase the wait time exponentially if the task has been finished before the next polling cycle.

Calling a function for each retry attempt

Is there any way that we can pass in a function as an option which is called for each retry?

I'm looking to log retry attempts as they happen, preferably with the attempt number included.

dist missing

It seems like versions 1.2.0 and 2.0.0 are missing the dist folder in the npm package.

temp $ npm install [email protected]
+ [email protected]
added 1 package from 1 contributor and audited 1 package in 1.945s
found 0 vulnerabilities

temp $ cd node_modules/exponential-backoff/
exponential-backoff $ ls
LICENSE		README.md	dist		package.json
exponential-backoff $ cd ..
node_modules $ cd ..
temp $ rm -rf node_modules/
temp $ npm install [email protected]
+ [email protected]
added 1 package from 1 contributor and audited 1 package in 0.664s
found 0 vulnerabilities
temp $ cd node_modules/exponential-backoff/
exponential-backoff $ ls
LICENSE		README.md	package.json
exponential-backoff $ cd ..
node_modules $ cd ..
temp $ rm -rf node_modules/
temp $ npm install [email protected]
+ [email protected]
added 1 package from 1 contributor and audited 1 package in 0.693s
found 0 vulnerabilities

temp $ cd node_modules/exponential-backoff/
exponential-backoff $ ls
LICENSE		README.md	doc		package.json

IBackOffOptions aren't optional

None of the properties of IBackOffOptions are optional, even though the Readme states that they all are:

export interface IBackOffOptions {
  delayFirstAttempt: boolean;
  jitter: JitterType;
  maxDelay: number;
  numOfAttempts: number;
  retry: (e: any, attemptNumber: number) => boolean | Promise<boolean>;
  startingDelay: number;
  timeMultiple: number;
}

What is the units of maxDelay?

The documentation does not describe the units of the maxDelay option. I assume it's milliseconds (ms), but it should be documented in the README.

Detect attempt limit reached

The current codebase has a private typescript property attemptLimitReached, which happens to work when used by non typescript implementations, but with a more modern TS implementation will make this property private as well.

As a feature being able to detect the limit being reached is fairly essential. Is there any way to expose a getter or method to detect this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.