{"action":"created","issue":{"url":"https://api.github.com/repos/RxSwiftCommunity/RxSwift-Ext/issues/15","repository_url":"https://api.github.com/repos/RxSwiftCommunity/RxSwift-Ext","labels_url":"https://api.github.com/repos/RxSwiftCommunity/RxSwift-Ext/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/RxSwiftCommunity/RxSwift-Ext/issues/15/comments","events_url":"https://api.github.com/repos/RxSwiftCommunity/RxSwift-Ext/issues/15/events","html_url":"https://github.com/RxSwiftCommunity/RxSwift-Ext/issues/15","id":148148800,"number":15,"title":"retryWithDelay","user":{"login":"brunogb","id":62097,"avatar_url":"https://avatars.githubusercontent.com/u/62097?v=3","gravatar_id":"","url":"https://api.github.com/users/brunogb","html_url":"https://github.com/brunogb","followers_url":"https://api.github.com/users/brunogb/followers","following_url":"https://api.github.com/users/brunogb/following{/other_user}","gists_url":"https://api.github.com/users/brunogb/gists{/gist_id}","starred_url":"https://api.github.com/users/brunogb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brunogb/subscriptions","organizations_url":"https://api.github.com/users/brunogb/orgs","repos_url":"https://api.github.com/users/brunogb/repos","events_url":"https://api.github.com/users/brunogb/events{/privacy}","received_events_url":"https://api.github.com/users/brunogb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/RxSwiftCommunity/RxSwift-Ext/labels/proposed%20Operator","name":"proposed Operator","color":"1d76db"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-13T18:45:27Z","updated_at":"2016-04-15T08:56:01Z","closed_at":null,"body":"### Name and description\r\n\r\n`retryWithDelay(numberOfAttempts: Int, delayIncrease: Double)`\r\n\r\n\r\n### Motivation for inclusion\r\n\r\nAllows an operation to wait some time before trying again in case of error. Also allow for increment the waiting after each failed attempt\r\n\r\n### Example of use\r\n\r\nWe could use this operator like a \"Retry to connect in\" that we seen in many communicators app. \r\nSometimes it may be better to wait some time before trying an operation again.\r\n\r\n### Suggested implementation\r\nThis was a suggested implementation made by @mjohnson (on rxSwift slack). I plan to improve in this solution allowing for better parametrisation\r\n\r\n```swift\r\n.retryWhen { (attempts) in\r\n        return Observable.zip(attempts, Observable.range(start: 1, count: 4)) { n, i in\r\n            return (n, i)\r\n            }.flatMap { (n, i) in\r\n                \r\n                return i >= 4 ? Observable.error(n) : Observable<Int>.timer(RxTimeInterval(i), scheduler: MainScheduler.instance)\r\n        }\r\n```"},"comment":{"url":"https://api.github.com/repos/RxSwiftCommunity/RxSwift-Ext/issues/comments/210369701","html_url":"https://github.com/RxSwiftCommunity/RxSwift-Ext/issues/15#issuecomment-210369701","issue_url":"https://api.github.com/repos/RxSwiftCommunity/RxSwift-Ext/issues/15","id":210369701,"user":{"login":"fpillet","id":166018,"avatar_url":"https://avatars.githubusercontent.com/u/166018?v=3","gravatar_id":"","url":"https://api.github.com/users/fpillet","html_url":"https://github.com/fpillet","followers_url":"https://api.github.com/users/fpillet/followers","following_url":"https://api.github.com/users/fpillet/following{/other_user}","gists_url":"https://api.github.com/users/fpillet/gists{/gist_id}","starred_url":"https://api.github.com/users/fpillet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fpillet/subscriptions","organizations_url":"https://api.github.com/users/fpillet/orgs","repos_url":"https://api.github.com/users/fpillet/repos","events_url":"https://api.github.com/users/fpillet/events{/privacy}","received_events_url":"https://api.github.com/users/fpillet/received_events","type":"User","site_admin":false},"created_at":"2016-04-15T08:56:01Z","updated_at":"2016-04-15T08:56:01Z","body":"Ok more thoughts about this excellent idea for an operator. I think we can implement several possible variations to cover the full spectrum:\r\n\r\n**Retry with a fixed delay at each iteration:**\r\n`retry(maxAttemptCount : Int, delay : Double)`\r\n\r\n**Retry with a fixed delay increase at each iteration, optionally providing the initial delay:**\r\n`retry(maxAttemptCount : Int, initialDelay : Double = 0, delayIncrease : Double)`\r\n\r\n**Retry with a growing delay as a percentage of previous delay:**\r\n`retry(maxAttemptCount : Int, initialDelay : Double, delayPercentIncrease : Double)`\r\n\r\nI am tempted to make `maxAttemptCount` an `@autoclosure () -> Int` instead of a simple `Int`. This would let developer pass a function that can conditionally cancel the delayed retry. But I fear this may only confuse most readers. Moreover, for complex cases one can use `retryWhen` as the implementation for this operator will do."}}