Coder Social home page Coder Social logo

Add `onReattempt` option about p-retry HOT 8 CLOSED

sindresorhus avatar sindresorhus commented on September 16, 2024
Add `onReattempt` option

from p-retry.

Comments (8)

sindresorhus avatar sindresorhus commented on September 16, 2024 1

When would it call onError? Can you elaborate on what you need and how you would use it?

from p-retry.

kilianc avatar kilianc commented on September 16, 2024
await retry(() => foo(), {
  onError: (err, attemptNumber, attemptsLeft) => {
    console.error(`Attempt number ${attemptNumber} failed: ${err.message} (${attemptsLeft} left)`)
  }
})

from p-retry.

sindresorhus avatar sindresorhus commented on September 16, 2024

@kilianc I mean, in what situation would node-retry call the onError function you supply? From your example, it seems like rejecting the promise might be a better option and including the attemptNumber and attemptsLeft as properties on the error.

from p-retry.

SamVerschueren avatar SamVerschueren commented on September 16, 2024

I think what @kilianc wants is a function to be called after every failed attempt so you can show status updates on network requests or something. So if we go for it, it might be better to call the function onFailure instead of onError.

from p-retry.

kilianc avatar kilianc commented on September 16, 2024

@SamVerschueren correct. It's mostly for network reattempts. onFailure and onError sound exactly the same. maybe onReattempt ?

from p-retry.

sindresorhus avatar sindresorhus commented on September 16, 2024

onReattempt 👍

I assume this would only be called on the second attempt and forward?

from p-retry.

kilianc avatar kilianc commented on September 16, 2024

onFailedAttempt ?

from p-retry.

acostalima avatar acostalima commented on September 16, 2024

I've just pushed PR #5 to add this feature. 😄

from p-retry.

Related Issues (20)

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.