{"id":16061700,"url":"https://github.com/mattmassicotte/queue","last_synced_at":"2025-04-06T16:11:50.870Z","repository":{"id":175631161,"uuid":"654151510","full_name":"mattmassicotte/Queue","owner":"mattmassicotte","description":"A queue for Swift concurrency","archived":false,"fork":false,"pushed_at":"2024-08-16T10:48:18.000Z","size":80,"stargazers_count":257,"open_issues_count":0,"forks_count":8,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-10T04:09:38.725Z","etag":null,"topics":["concurrency","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattmassicotte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["mattmassicotte"]}},"created_at":"2023-06-15T13:46:45.000Z","updated_at":"2024-10-10T03:34:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d6fe8b0-514d-4916-960d-801c603aeccb","html_url":"https://github.com/mattmassicotte/Queue","commit_stats":null,"previous_names":["mattmassicotte/queue"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmassicotte%2FQueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmassicotte%2FQueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmassicotte%2FQueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmassicotte%2FQueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattmassicotte","download_url":"https://codeload.github.com/mattmassicotte/Queue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509223,"owners_count":20950232,"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":["concurrency","swift"],"created_at":"2024-10-09T04:09:42.097Z","updated_at":"2025-04-06T16:11:50.848Z","avatar_url":"https://github.com/mattmassicotte.png","language":"Swift","funding_links":["https://github.com/sponsors/mattmassicotte"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n[![Build Status][build status badge]][build status]\n[![Platforms][platforms badge]][platforms]\n[![Documentation][documentation badge]][documentation]\n[![Matrix][matrix badge]][matrix]\n\n\u003c/div\u003e\n\n# Queue\n\nA queue for Swift concurrency\n\nThis package exposes a single type: `AsyncQueue`. Conceptually, `AsyncQueue` is very similar to a `DispatchQueue` or `OperationQueue`. However, unlike these an `AsyncQueue` can accept async blocks. This exists to more easily enforce ordering across unstructured tasks without requiring explicit dependencies between them.\n\nI've found this helpful when interfacing stateful asynchronous systems with synchronous code.\n\nIf you are looking for help handling actor reentrancy, check out [Lock](https://github.com/mattmassicotte/Lock) and [Semaphore][semaphore].\n\n## Integration\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/mattmassicotte/Queue\", from: \"0.2.0\")\n]\n```\n\n## Usage\n\n```swift\nlet queue = AsyncQueue()\n\nqueue.addOperation {\n    await asyncFunction()\n    await anotherAsyncFunction()\n}\n\n// This can can also return the underlying Task,\n// so you can cancel, or await a value\nlet task = queue.addOperation {\n    return await makeValue()\n}\n\nlet value = try await task.value\n```\n\nBy default, `AsyncQueue` will only run one operation at a time. But, it can be configured as a concurrent queue.\n\n```swift\nlet queue = AsyncQueue(attributes: [.concurrent])\n\n// these two may run concurrently\nqueue.addOperation { await asyncFunction() }\nqueue.addOperation { await asyncFunction() }\n\n// This will only run once existing operations are complete, and will\n// prevent new operations from starting until done\nqueue.addBarrierOperation {\n    await asyncFunction()\n}\n```\n\nThe `AsyncQueue` type has an `errorSequence` property, which can be used to detect uncaught errors out of band.\n\n```swift\nlet queue = AsyncQueue(attributes: [.publishErrors])\n\nTask {\n    for await error in queue.errorSequence {\n        print(error)\n    }\n}\n```\n\nThis package was inspired by [Semaphore][semaphore], which is another concurrency-related synchronization system that I've found very useful.\n\n## Alternatives\n\n- [swift-async-queue](https://github.com/dfed/swift-async-queue)\n\n## Contributing and Collaboration\n\nI would love to hear from you! Issues or pull requests work great. Both a [Matrix space][matrix] and [Discord][discord] are available for live help, but I have a strong bias towards answering in the form of documentation. You can also find me [here](https://www.massicotte.org/about).\n\nI prefer collaboration, and would love to find ways to work together if you have a similar project.\n\nI prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.\n\nBy participating in this project you agree to abide by the [Contributor Code of Conduct](CODE_OF_CONDUCT.md).\n\n[build status]: https://github.com/mattmassicotte/Queue/actions\n[build status badge]: https://github.com/mattmassicotte/Queue/workflows/CI/badge.svg\n[platforms]: https://swiftpackageindex.com/mattmassicotte/Queue\n[platforms badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmattmassicotte%2FQueue%2Fbadge%3Ftype%3Dplatforms\n[documentation]: https://swiftpackageindex.com/mattmassicotte/Queue/main/documentation\n[documentation badge]: https://img.shields.io/badge/Documentation-DocC-blue\n[matrix]: https://matrix.to/#/%23chimehq%3Amatrix.org\n[matrix badge]: https://img.shields.io/matrix/chimehq%3Amatrix.org?label=Matrix\n[discord]: https://discord.gg/esFpX6sErJ\n[semaphore]: https://github.com/groue/Semaphore\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmassicotte%2Fqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattmassicotte%2Fqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmassicotte%2Fqueue/lists"}