{"id":22477745,"url":"https://github.com/swiftuiux/async-task","last_synced_at":"2025-12-11T22:51:00.930Z","repository":{"id":265044812,"uuid":"894957481","full_name":"swiftuiux/async-task","owner":"swiftuiux","description":"A Swift package providing tools and types for managing async task lib. This package is designed to simplify the handling of cancellable asynchronous operations in SwiftUI by offering reusable view models and patterns concurency. Async task swift and swiftui An async library for Swift Task manager Task kit concurrency Queue task operation elements","archived":false,"fork":false,"pushed_at":"2025-08-14T16:37:47.000Z","size":78,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-09-27T21:49:20.861Z","etag":null,"topics":["kit","task"],"latest_commit_sha":null,"homepage":"","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/swiftuiux.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,"zenodo":null}},"created_at":"2024-11-27T10:01:03.000Z","updated_at":"2025-08-14T11:30:15.000Z","dependencies_parsed_at":"2025-07-25T10:11:46.021Z","dependency_job_id":"e61d4f3e-d65b-4504-b332-1a262887d55e","html_url":"https://github.com/swiftuiux/async-task","commit_stats":null,"previous_names":["igor11191708/async-task","swiftuiux/async-task"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/swiftuiux/async-task","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fasync-task","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fasync-task/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fasync-task/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fasync-task/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swiftuiux","download_url":"https://codeload.github.com/swiftuiux/async-task/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fasync-task/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27672062,"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","status":"online","status_checked_at":"2025-12-11T02:00:11.302Z","response_time":56,"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":["kit","task"],"created_at":"2024-12-06T14:12:08.034Z","updated_at":"2025-12-11T22:51:00.911Z","avatar_url":"https://github.com/swiftuiux.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async Task Kit\n\n### Please star the repository if you believe continuing the development of this package is worthwhile. This will help me understand which package deserves more effort.\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswiftuiux%2Fasync-task%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swiftuiux/async-task)\n\n**Async Task Kit** is a Swift package designed to simplify the management of cancellable asynchronous tasks. It provides reusable tools and patterns for handling asynchronous operations in SwiftUI applications.\n\n## Examples in SwiftUI\n\nExplore real examples of how to use this package in SwiftUI and how it can simplify the code:\n\n1. [Async Location](https://github.com/swiftuiux/corelocation-manager-tracker-swift-apple-maps-example)\n2. [Replicate Kit](https://github.com/swiftuiux/replicate-kit-example)\n3. [OpenAI AsyncImage](https://github.com/swiftuiux/openai-async-image-swiftui)\n\n## Overview\n\nAsync Task Kit provides tools to manage asynchronous tasks efficiently, with features such as:\n- **State Management:** Monitor task progress, results, and errors using reactive properties.\n- **Task Cancellation:** Cancel running tasks to free up resources when no longer needed.\n- **Customizable Error Handling:** Define custom error-handling logic tailored to your application.\n- **Seamless SwiftUI Integration:** Uses `@Published` properties for real-time UI updates or @observable is you can afford iOS17 or newer.\n- **`Async.SingleTask`:** A view model for managing a single cancellable asynchronous task.\n\n## Usage\n\n### `Async.SingleTask`\n\nThe `Async.SingleTask` class simplifies managing a single asynchronous task. It tracks the task's result, error state, and activity status, making it ideal for use in SwiftUI views.\n\n### Example: Fetching Data With Input\nBelow is an example of processing an input asynchronously using Async.SingleTask and producing a transformed output.\n\n```swift\nstruct ProcessInputView: View {\n    @StateObject private var viewModel = Async.SingleTask\u003cInt, Error\u003e()\n\n    private var value: String? { viewModel.value }\n\n    private var error: String? { viewModel.error?.localizedDescription }\n\n    private var isActive: Bool { viewModel.state == .active }\n\n    var body: some View {\n        VStack {\n            if let value {\n                Text(\"Result: \\(value)\")\n            } else if let error {\n                Text(\"Error: \\(error)\")\n            } else if isActive {\n                ProgressView(\"Loading...\")\n            } else {\n                Button(\"Process Input\", action: processInput)\n            }\n        }\n    }\n\n    private func processInput() {\n        viewModel.start(with: 21) { input in\n            try await performAsyncProcessing(for: input)\n        }\n    }\n\n    private func performAsyncProcessing(for input: Int) async throws -\u003e Int {\n        try await Task.sleep(nanoseconds: 1 * 1_000_000_000) // Simulate a 1-second delay\n        return input * 2\n    }\n}\n```\n\n### `Async.ObservableSingleTask`\nFor projects targeting iOS 17 and above, you can use Async.ObservableSingleTask, which leverages the new @Observable macro for more efficient state observation in SwiftUI.\n\n### Example: Fetching Data Without Input Using ObservableSingleTask\n\n```swift\n@available(iOS 17.0, *)\nstruct ObservableCustomErrorView: View {\n\n    @State private var viewModel = Async.ObservableSingleTask\u003cString, CustomError\u003e(errorMapper: customErrorMapper)\n\n    var body: some View {\n        VStack {\n            if let value = viewModel.value {\n                Text(\"Result: \\(value)\")\n            } else if let error = viewModel.error {\n                Text(\"Error: \\(error)\")\n            } else if viewModel.state == .active {\n                ProgressView(\"Loading...\")\n            } else {\n                Button(\"Fetch Data\", action: fetchData)\n            }\n        }\n    }\n\n    private func fetchData() {\n        viewModel.start {\n            try await performAsyncFetch()\n        }\n    }\n\n    private func performAsyncFetch() async throws -\u003e String {\n        // Simulate an error\n        throw NSError(domain: \"Network\", code: -1, userInfo: [NSLocalizedDescriptionKey: \"Unable to reach server\"])\n    } \n}\n\n    enum CustomError: Error {\n        case networkError(String)\n    }\n\n    let customErrorMapper: Async.ErrorMapper\u003cCustomError\u003e = { error in\n        return .networkError(error.localizedDescription)\n    }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftuiux%2Fasync-task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiftuiux%2Fasync-task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftuiux%2Fasync-task/lists"}