{"id":3032,"url":"https://github.com/icanzilb/Retry","last_synced_at":"2025-08-03T12:31:55.347Z","repository":{"id":62452861,"uuid":"66542034","full_name":"icanzilb/Retry","owner":"icanzilb","description":"Haven't you wished for `try` to sometimes try a little harder? Meet `retry`","archived":false,"fork":false,"pushed_at":"2021-10-21T16:06:25.000Z","size":55,"stargazers_count":499,"open_issues_count":2,"forks_count":16,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-11-23T23:02:25.312Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icanzilb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-25T08:54:21.000Z","updated_at":"2024-10-01T03:53:11.000Z","dependencies_parsed_at":"2022-11-01T23:46:25.201Z","dependency_job_id":null,"html_url":"https://github.com/icanzilb/Retry","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanzilb%2FRetry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanzilb%2FRetry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanzilb%2FRetry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanzilb%2FRetry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icanzilb","download_url":"https://codeload.github.com/icanzilb/Retry/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228543258,"owners_count":17934451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:29.471Z","updated_at":"2024-12-07T00:31:12.383Z","avatar_url":"https://github.com/icanzilb.png","language":"Swift","funding_links":[],"categories":["Utility"],"sub_categories":["Web View","Other free courses"],"readme":"# Retry\n\n[![Version](https://img.shields.io/cocoapods/v/Retry.svg?style=flat)](http://cocoapods.org/pods/Retry)\n[![License](https://img.shields.io/cocoapods/l/Retry.svg?style=flat)](http://cocoapods.org/pods/Retry)\n[![Platform](https://img.shields.io/cocoapods/p/Retry.svg?style=flat)](http://cocoapods.org/pods/Retry)\n\n## Example\n\nHaven't you wished for `try` to sometimes try a little harder? Meet `retry`\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\nThe full test suite shows a variety of use cases.\n\n### Synchronous retry\n\nNB: The sync `retry` is not good for use on the main thread (because it will block it if you're having delays, etc). For the main thread it's better considering `retryAsync` (more info below).\n\nDefault parameters - retry three times without any delay:\n\n```swift\nretry {\n  ... do some throwing work ...\n}\n```\n\nCatching the last error, and adding a defer block after all tries have finished - will keep trying maximum `10` times. You can use either of the final blocks or both:\n\n```swift\nretry (max: 10) {\n  ... do some throwing work ...\n}\n.finalCatch {lastError in\n  print(\"This simply won't happen. Failed with: \\(lastError)\")\n}\n.finalDefer {\n  print(\"Finished trying\")\n}\n```\n\nAdd `2` second delay between the retries:\n\n```swift\nretry (max: 5, retryStrategy: .delay(seconds: 2.0)) {\n  ... do some throwing work ...\n}\n```\n\nImplement any custom delay logic (below is multiplying the waiting time after each try):\n\n```swift\nretry (max: 5, retryStrategy: .custom {count, lastDelay in return (lastDelay ?? 1.0) * 2.0} ) {\n  ... do some throwing work ...\n}\n```\n\nLimit the number of retries based on any custom logic - if you return `nil` from your custom strategy, `retry` will stop trying:\n\n```swift\nretry (max: 5, retryStrategy: .custom {count,_ in return count \u003e 3 ? nil : 0} ) {\n  ... do some throwing work ...\n}\n```\n\n### Asynchronous retry\n\nThe syntax for `retryAsync` is exactly the same as for `retry`. The difference in behavior is if the first try fails `retryAsync` keeps trying asynchronously instead of blocking the current thread.\n\n## Installation\n\nRetry is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"Retry\"\n```\n\nRetry is also available through Swift Package Manager. To install, add `https://github.com/icanzilb/Retry.git` to your package manifest.\n\nSince Retry is a swift3 library, you got to add this piece of code to your project's Podfile, to update your targets' swift language version:\n\n```\npost_install do |installer|\n    installer.pods_project.targets.each do |target|\n        target.build_configurations.each do |config|\n            config.build_settings['SWIFT_VERSION'] = '3.0'\n            config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.10'\n        end\n    end\nend\n```\n\n## Author\n\nMarin Todorov, 2016-present\n\nInspired by the retry operator in https://github.com/RxSwiftCommunity/RxSwiftExt\n\n## License\n\nRetry is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficanzilb%2FRetry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficanzilb%2FRetry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficanzilb%2FRetry/lists"}