Feat: Add Abort Signal Implementation
- In my application, I needed to optionally add
AbortSignalto terminate retry logic. - This PR implements the ability to pass an
AbortSignalto the retry logic. This will allow the user to cancel the retry logic if needed. - To support
AbortConrollerin typescript types, I bumped@types/nodeto22.4.1version
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?
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
falsein the retry function?
Maybe react useEffect?
useEffect(() => {
backOff(() => {}, { signal: signal })
return () => { signal.abort() }
}, [id])
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.
Happy to pick up addressing the code review if @developertom01 has moved on to other things in the last year.