Retrying network request for set amount of time
See original GitHub issueHey, I understand this is a “how to” question, and this might not be the place for it. If so, feel free to close ticket, and I’ll open elsewhere.
I’m implementing payments against a very retro (I’m being nice here 😉 ) API, and can’t rely on the redirect after payment to contain the correct status. After payment, the payment provider makes a callback to a URL specified by us, which updates the order, which I have to check against. What I’d like to achieve in a semi-sensible way is this:
- User lands on page, start saga
- For 10 seconds (a
race
I imagine),call
the order endpoint every 2 seconds to see if the order has the correct status - If the request “fails” (promise rejects), keep retrying
- If the request “succeeds” (promise resolves), end race
- After 10 seconds, if the request hasn’t succeeded, assume “fails”.
I understand the race concept and have implemented it elsewhere, I’m just not sure how to do the “retry every 2 seconds” and fit it in there. Any thoughts?
If you feel this warrants an extra page under “Advanced Concepts” I’d be happy to write it and contribute it back.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
You’ll have to throw the error instead of returing it
yes; throwing instead of returning is because you catch in the containing saga, so you’re expecting the subsaga to throw errors instead of returning them