exponential-backoff icon indicating copy to clipboard operation
exponential-backoff copied to clipboard

Feat: Add Abort Signal Implementation

Open developertom01 opened this issue 1 year ago • 4 comments

  • In my application, I needed to optionally add AbortSignal to terminate retry logic.
  • This PR implements the ability to pass an AbortSignal to the retry logic. This will allow the user to cancel the retry logic if needed.
  • To support AbortConroller in typescript types, I bumped @types/node to 22.4.1 version

developertom01 avatar Aug 20 '24 22:08 developertom01

Could you describe the scenario that requires using the Abort API? Some pseudocode could be helpful,

Is it possible to end the retry by returning false in the retry function?

samisayegh avatar Feb 04 '25 21:02 samisayegh

Could you describe the scenario that requires using the Abort API? Some pseudocode could be helpful,

Is it possible to end the retry by returning false in the retry function?

Maybe react useEffect?

useEffect(() => {
    backOff(() => {}, { signal: signal })

    return () => { signal.abort()  }
}, [id])

heyppen avatar Feb 26 '25 13:02 heyppen

My use case is for a polling script that has a graceful shutdown function where receiving a SIGTERM will start cleaning up and sending a signal to abort. The graceful shutdown also has a timeout to exit if everything isn't cleaned up by then.

For a more specific scenario, the built-in fetch API takes in an Abort signal to stop the http request. Normally this wouldn't be an issue, but if you wrap this retry library around the fetch call, this library will go through all the retries, which may be lengthy. If the library can handle the same signal that was passed to the fetch API, then the library could also abort the retrying.

bliu13 avatar Feb 26 '25 14:02 bliu13

Happy to pick up addressing the code review if @developertom01 has moved on to other things in the last year.

kav avatar Aug 29 '25 22:08 kav