{"action":"created","issue":{"url":"https://api.github.com/repos/danthorpe/Operations/issues/243","repository_url":"https://api.github.com/repos/danthorpe/Operations","labels_url":"https://api.github.com/repos/danthorpe/Operations/issues/243/labels{/name}","comments_url":"https://api.github.com/repos/danthorpe/Operations/issues/243/comments","events_url":"https://api.github.com/repos/danthorpe/Operations/issues/243/events","html_url":"https://github.com/danthorpe/Operations/issues/243","id":142316960,"number":243,"title":"Example for RetryOperation","user":{"login":"vamsiac","id":352707,"avatar_url":"https://avatars.githubusercontent.com/u/352707?v=3","gravatar_id":"","url":"https://api.github.com/users/vamsiac","html_url":"https://github.com/vamsiac","followers_url":"https://api.github.com/users/vamsiac/followers","following_url":"https://api.github.com/users/vamsiac/following{/other_user}","gists_url":"https://api.github.com/users/vamsiac/gists{/gist_id}","starred_url":"https://api.github.com/users/vamsiac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vamsiac/subscriptions","organizations_url":"https://api.github.com/users/vamsiac/orgs","repos_url":"https://api.github.com/users/vamsiac/repos","events_url":"https://api.github.com/users/vamsiac/events{/privacy}","received_events_url":"https://api.github.com/users/vamsiac/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/danthorpe/Operations/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-21T11:11:13Z","updated_at":"2016-03-21T15:13:15Z","closed_at":null,"body":"Struggling to find a way to generate RetryOperation?\r\n\r\n```\r\nlet uploadOp = PostMachineUpdateOperation()\r\n\r\nuploadOp.addObserver(DidFinishObserver { operation,errors in\r\n   if let error = errors.first! as ErrorType? {\r\n                let errOperation = AppAlertOperation(error: error, from: self)\r\n                self.operationQueue.addOperation(errOperation)\r\n\r\n                errOperation.alert.addAction(UIAlertAction(title: \"Retry\", style: UIAlertActionStyle.Default, handler: { action in\r\n\r\n      //HOW TO CREATE A RETRY OPERATION?\r\n      let operation = RetryOperation(anyGenerator(PostMachineUpdateOperation()), retry: retry)\r\n                    self.operationQueue.addOperation(operation)\r\n\r\n             })\r\n\r\n    }\r\n})\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/danthorpe/Operations/issues/comments/199332218","html_url":"https://github.com/danthorpe/Operations/issues/243#issuecomment-199332218","issue_url":"https://api.github.com/repos/danthorpe/Operations/issues/243","id":199332218,"user":{"login":"danthorpe","id":309420,"avatar_url":"https://avatars.githubusercontent.com/u/309420?v=3","gravatar_id":"","url":"https://api.github.com/users/danthorpe","html_url":"https://github.com/danthorpe","followers_url":"https://api.github.com/users/danthorpe/followers","following_url":"https://api.github.com/users/danthorpe/following{/other_user}","gists_url":"https://api.github.com/users/danthorpe/gists{/gist_id}","starred_url":"https://api.github.com/users/danthorpe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danthorpe/subscriptions","organizations_url":"https://api.github.com/users/danthorpe/orgs","repos_url":"https://api.github.com/users/danthorpe/repos","events_url":"https://api.github.com/users/danthorpe/events{/privacy}","received_events_url":"https://api.github.com/users/danthorpe/received_events","type":"User","site_admin":false},"created_at":"2016-03-21T15:13:15Z","updated_at":"2016-03-21T15:13:15Z","body":"I think in the unit tests, because I need to create operations, which fail N times and then succeed, I have that logic wrapped up into a `produce` function, which is just returning a closure. i.e.\r\n\r\n```swift\r\nfunc produce() -> () -> PostMachineUpdateOperation? {\r\n    // Return a closure\r\n    return {\r\n        // Return an instance of PostMachineUpdateOperation or nil\r\n    }\r\n}\r\n```\r\n\r\nGiven something like that you can then also do:\r\n\r\n```swift\r\nlet operation = RetryOperation(anyGenerator(produce()), retry: retry)\r\n```"}}