{"id":19024162,"url":"https://github.com/raykitajima/asynctimeout","last_synced_at":"2026-06-21T15:31:54.227Z","repository":{"id":195293207,"uuid":"692638388","full_name":"RayKitajima/AsyncTimeout","owner":"RayKitajima","description":"A Swift utility provides timeout for async func","archived":false,"fork":false,"pushed_at":"2023-09-24T07:04:51.000Z","size":4,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-01T08:00:05.714Z","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/RayKitajima.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-17T05:31:59.000Z","updated_at":"2025-03-11T06:42:48.000Z","dependencies_parsed_at":"2023-09-17T10:42:18.364Z","dependency_job_id":"639241f2-6d10-4ac2-9ced-a3fa02b023f3","html_url":"https://github.com/RayKitajima/AsyncTimeout","commit_stats":null,"previous_names":["raykitajima/asynctimeout"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/RayKitajima/AsyncTimeout","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayKitajima%2FAsyncTimeout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayKitajima%2FAsyncTimeout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayKitajima%2FAsyncTimeout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayKitajima%2FAsyncTimeout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RayKitajima","download_url":"https://codeload.github.com/RayKitajima/AsyncTimeout/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayKitajima%2FAsyncTimeout/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34616509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-08T20:35:22.932Z","updated_at":"2026-06-21T15:31:54.209Z","avatar_url":"https://github.com/RayKitajima.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# AsyncTimeout\n\nA Swift utility that provides a timeout mechanism for asynchronous operations using the new async/await syntax introduced in Swift 5.5.\n\n## Features:\n- Compatibility with iOS 13.0+ and macOS 10.15+\n- Uses Swift's new concurrency features such as `actor` and `TaskGroup`\n- Throws a `timeout` error if the operation doesn't complete within the specified timeout.\n\n## How to Use:\n\n1. Ensure that you're using Swift 5.5 or later and targeting at least iOS 13.0 or macOS 10.15.\n2. Integrate the `AsyncTimeout` structure into your project.\n3. Use the static `withTimeout` function to wrap the async operation that you want to time out.\n\n### Swift Package Manager\n\nAdd the following to your Package.swift dependencies:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/RayKitajima/AsyncTimeout.git\", from: \"1.0.0\"),\n],\n```\n\n### Example:\n\n```swift\nimport AsyncTimeout\n\ndo {\n    let result: YourReturnType = try await AsyncTimeout.withTimeout(seconds: 5) {\n        return try await someAsyncFunc()\n    }\n} catch AsyncTimeout.CustomError.timeout {\n    print(\"The operation timed out!\")\n} catch {\n    print(\"An error occurred: \\(error.localizedDescription)\")\n}\n```\n\n## Details:\n\n### Structs \u0026 Enums:\n\n- `AsyncTimeout`: The main struct containing the timeout logic.\n- `OperationState`: An actor that tracks if the operation has been completed. It's used to safely handle state across potentially concurrent code.\n- `CustomError`: An enum that has a `timeout` case, representing a timeout error.\n\n### Main Function:\n\n- `withTimeout(seconds:operation:)`: This function takes a timeout interval (in seconds) and an async operation. If the operation doesn't complete within the given timeout, it throws a timeout error.\n\n## Notes:\n\n- The utility employs a polling mechanism to check if the operation has completed. The current check interval is set at 0.1 seconds. This might lead to a maximum delay of 0.1 seconds more than the specified timeout.\n\n## Disclaimer:\n\n- The function assumes that the provided async operation will complete successfully, i.e., the result is forcefully unwrapped at the end (`result!`). It's essential to ensure the operation doesn't result in a nil value, or it will crash.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraykitajima%2Fasynctimeout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraykitajima%2Fasynctimeout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraykitajima%2Fasynctimeout/lists"}