Skip to content

Commit fa9543e

Browse files
committed
update
1 parent 6c88c90 commit fa9543e

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

Sources/async-task/enum/State.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Igor Shelopaev on 29.11.24.
66
//
77

8-
public extension Async {
8+
extension Async {
99
/// Represents the current state of an asynchronous operation.
1010
///
1111
/// Use the `State` enum to track whether an asynchronous task is idle or actively running.
@@ -15,7 +15,7 @@ public extension Async {
1515
/// - `idle`: Indicates that no task is currently running.
1616
/// - `active`: Indicates that a task is currently in progress.
1717
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
18-
enum State {
18+
public enum State: Sendable, Hashable {
1919
/// No task is currently running.
2020
case idle
2121

Sources/async-task/enum/TaskProperty.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extension Async {
99

1010
/// An enumeration representing the properties of an asynchronous task that can be reset.
1111
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
12-
enum TaskProperty {
12+
public enum TaskProperty: Sendable, Hashable {
1313

1414
/// Represents the `error` property of a task.
1515
case error

Sources/async-task/protocol/IAsyncTask.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Foundation
1717
/// ensuring thread safety for UI-related operations.
1818
@MainActor
1919
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
20-
public protocol IAsyncTask: AnyObject, Sendable {
20+
public protocol IAsyncTask: AnyObject{
2121

2222
/// The type of the value produced by the asynchronous task.
2323
associatedtype Value: Sendable
@@ -90,8 +90,7 @@ public protocol IAsyncTask: AnyObject, Sendable {
9090

9191
/// Executes an asynchronous operation and manages its lifecycle.
9292
///
93-
/// This private method centralizes the common functionality for running an asynchronous task.
94-
/// It resets the current state, starts the task, manages errors, and updates the task's state.
93+
/// This requirement centralizes the common functionality for running an asynchronous task.
9594
///
9695
/// - Parameters:
9796
/// - priority: The priority of the task, which determines its scheduling priority in the system.

Sources/async-task/task/ObservableSingleTask.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import SwiftUI
99

1010
#if compiler(>=5.9) && canImport(Observation)
11+
import Observation
1112

1213
extension Async {
1314

@@ -18,8 +19,12 @@ extension Async {
1819
@MainActor
1920
@Observable
2021
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
21-
public final class ObservableSingleTask<V: Sendable, E: Error>: IAsyncTask {
22-
22+
public final class ObservableSingleTask<V: Sendable, E: Error & Sendable>: IAsyncTask {
23+
24+
public typealias Value = V
25+
26+
public typealias ErrorType = E
27+
2328
// MARK: - Public Properties
2429

2530
/// The error encountered during the task, if any.
@@ -52,10 +57,10 @@ extension Async {
5257
/// - Parameter errorMapper: A closure for custom error handling, allowing transformation of
5358
/// errors into the specified error type `E`. Defaults to `nil`.
5459
public init(
55-
errorMapper: Async.ErrorMapper<ErrorType>? = nil
60+
errorMapper: ErrorMapper<E>? = nil
5661
) {
5762
self.errorMapper = errorMapper
58-
}
63+
}
5964

6065
// MARK: - Public Methods
6166

@@ -83,7 +88,7 @@ extension Async {
8388
clean()
8489
setState(.active)
8590

86-
task = Task<Void, Never>(priority: priority) { [weak self] in
91+
task = Task<Void, Never>(priority: priority) { @MainActor [weak self] in
8792
defer {
8893
self?.setState(.idle)
8994
self?.task = nil

Sources/async-task/task/SingleTask.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ extension Async {
1818
/// occur on the main thread, making it safe for use in UI-related contexts.
1919
@MainActor
2020
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
21-
public final class SingleTask<V: Sendable, E: Error>: ObservableObject, IAsyncTask {
21+
public final class SingleTask<V: Sendable, E: Error & Sendable>: ObservableObject, IAsyncTask {
22+
23+
public typealias Value = V
24+
25+
public typealias ErrorType = E
2226

2327
// MARK: - Public Properties
2428

Sources/async-task/type/Type.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// Created by Igor Shelopaev on 29.11.24.
66
//
77

8-
public extension Async {
8+
extension Async {
99

1010
/// A closure type for handling errors.
1111
///
12-
/// This closure processes an optional `Error` and returns an optional custom error of type `E`.
12+
/// This closure processes an `Error` and returns an optional custom error of type `E`.
1313
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
14-
typealias ErrorMapper<E: Error & Sendable> = @Sendable (Error?) -> E?
14+
public typealias ErrorMapper<E: Error & Sendable> = @Sendable (Error) -> E?
1515

1616
/// A closure that asynchronously transforms an input of type `Input` into an output of type `Output`.
1717
///
@@ -25,7 +25,7 @@ public extension Async {
2525
/// when used in Swift's structured concurrency model.
2626
/// - Throws: An error if the asynchronous operation cannot complete successfully.
2727
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
28-
typealias Mapper<Input: Sendable, Output: Sendable> = @Sendable (Input) async throws -> Output
28+
public typealias Mapper<Input: Sendable, Output: Sendable> = @Sendable (Input) async throws -> Output
2929

3030
/// A closure that asynchronously produces an output of type `Output` without requiring any input.
3131
///
@@ -38,5 +38,5 @@ public extension Async {
3838
/// when used in Swift's structured concurrency model.
3939
/// - Throws: An error if the asynchronous operation cannot complete successfully.
4040
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
41-
typealias Producer<Output: Sendable> = @Sendable () async throws -> Output
41+
public typealias Producer<Output: Sendable> = @Sendable () async throws -> Output
4242
}

0 commit comments

Comments
 (0)