ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.58k stars 1.33k forks source link

Support tail off delay in retry #1644

Open ungrim97 opened 2 years ago

ungrim97 commented 2 years ago

Often when retrying a request it is useful to have a throttle back on the time between requests to prevent hitting the remote server in quick succession, but also to allow some time for potential issues to resolve.

I can see two potential ways that this could be easily handled in the .retry() function.

  1. Accept an array of intervals in ms similar to the interface for superagent-retyr-delay. Each interval would be applied per request in order

  2. Support the returing of promises in the callback function passed to retry. This would allow much greater scope for functionionality including the ability for the user to await some timeout before returning true/false.

The later is my preferred option, but returning Promises in callbacks is a bit...urgh.

I believe I can implement either option as a PR if desired.

margarita-lukjanska-cko commented 2 years ago

There seems to have been an attempt to implement async/await for retry: https://github.com/visionmedia/superagent/pull/1527

ungrim97 commented 2 years ago

Looks like that PR got merged which will solve the issue I was having so I will close this issue

ungrim97 commented 2 years ago

On second parse, it seems that the PR in #1527 were reverted so this ticket still needs to be open