{"action":"created","issue":{"url":"https://api.github.com/repos/yelouafi/redux-saga/issues/349","repository_url":"https://api.github.com/repos/yelouafi/redux-saga","labels_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/349/labels{/name}","comments_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/349/comments","events_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/349/events","html_url":"https://github.com/yelouafi/redux-saga/issues/349","id":156721355,"number":349,"title":"Retrying network request for set amount of time","user":{"login":"StevenLangbroek","id":296796,"avatar_url":"https://avatars.githubusercontent.com/u/296796?v=3","gravatar_id":"","url":"https://api.github.com/users/StevenLangbroek","html_url":"https://github.com/StevenLangbroek","followers_url":"https://api.github.com/users/StevenLangbroek/followers","following_url":"https://api.github.com/users/StevenLangbroek/following{/other_user}","gists_url":"https://api.github.com/users/StevenLangbroek/gists{/gist_id}","starred_url":"https://api.github.com/users/StevenLangbroek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StevenLangbroek/subscriptions","organizations_url":"https://api.github.com/users/StevenLangbroek/orgs","repos_url":"https://api.github.com/users/StevenLangbroek/repos","events_url":"https://api.github.com/users/StevenLangbroek/events{/privacy}","received_events_url":"https://api.github.com/users/StevenLangbroek/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yelouafi/redux-saga/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-25T10:58:05Z","updated_at":"2016-05-25T12:54:57Z","closed_at":null,"body":"Hey, 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.\r\n\r\nI'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:\r\n\r\n- User lands on page, start saga\r\n- For 10 seconds (a `race` I imagine), `call` the order endpoint every 2 seconds to see if the order has the correct status\r\n- If the request \"fails\" (promise rejects), keep retrying\r\n- If the request \"succeeds\" (promise resolves), end race\r\n- After 10 seconds, if the request hasn't succeeded, assume \"fails\".\r\n\r\nI 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?\r\n\r\nIf you feel this warrants an extra page under \"Advanced Concepts\" I'd be happy to write it and contribute it back."},"comment":{"url":"https://api.github.com/repos/yelouafi/redux-saga/issues/comments/221566740","html_url":"https://github.com/yelouafi/redux-saga/issues/349#issuecomment-221566740","issue_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/349","id":221566740,"user":{"login":"StevenLangbroek","id":296796,"avatar_url":"https://avatars.githubusercontent.com/u/296796?v=3","gravatar_id":"","url":"https://api.github.com/users/StevenLangbroek","html_url":"https://github.com/StevenLangbroek","followers_url":"https://api.github.com/users/StevenLangbroek/followers","following_url":"https://api.github.com/users/StevenLangbroek/following{/other_user}","gists_url":"https://api.github.com/users/StevenLangbroek/gists{/gist_id}","starred_url":"https://api.github.com/users/StevenLangbroek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StevenLangbroek/subscriptions","organizations_url":"https://api.github.com/users/StevenLangbroek/orgs","repos_url":"https://api.github.com/users/StevenLangbroek/repos","events_url":"https://api.github.com/users/StevenLangbroek/events{/privacy}","received_events_url":"https://api.github.com/users/StevenLangbroek/received_events","type":"User","site_admin":false},"created_at":"2016-05-25T12:54:56Z","updated_at":"2016-05-25T12:54:56Z","body":"Thanks for the quick reply. Would this be correct then?\r\n\r\n\r\nfunction* saga() {\r\n  for(let i = 1; i <= 5; i++) {\r\n    try {\r\n      const order = yield call(orderApi);\r\n      return order;\r\n    } catch(err) {\r\n      if(i < 5) {\r\n        yield call(delay, 2000);\r\n      }\r\n    }\r\n  }\r\n  // attempts failed after 5x2secs\r\n  return new Error('Order not fulfilled. Giving up.');\r\n}\r\n"}}
{"actor":{"display_login":"StevenLangbroek"}}