|
5 | 5 |
|
6 | 6 | import Foundation
|
7 | 7 |
|
8 |
| -// MARK: - ITaskFactory |
| 8 | +#if swift(>=6.0) |
9 | 9 |
|
10 |
| -// swiftlint:disable attributes |
11 |
| -/// A protocol for creating and managing tasks with different configurations. |
12 |
| -/// Provides methods to create tasks tied to the current actor context or detached tasks |
13 |
| -/// that run independently of the current actor. |
14 |
| -public protocol ITaskFactory { |
15 |
| - /// Creates a task tied to the current actor context that can throw errors. |
16 |
| - /// - Parameters: |
17 |
| - /// - priority: The priority of the task (optional). |
18 |
| - /// - operation: An asynchronous operation to execute within the task. The operation |
19 |
| - /// inherits the current actor context and is isolated to that actor. |
20 |
| - /// - Returns: A `Task` object that wraps the result or error of the operation. |
21 |
| - func task<Success: Sendable>( |
22 |
| - priority: TaskPriority?, |
23 |
| - @_inheritActorContext operation: sending @escaping @isolated(any) () async throws -> Success |
24 |
| - ) -> Task<Success, Error> |
| 10 | + // MARK: - ITaskFactory |
25 | 11 |
|
26 |
| - /// Creates a task tied to the current actor context that does not throw errors. |
27 |
| - /// - Parameters: |
28 |
| - /// - priority: The priority of the task (optional). |
29 |
| - /// - operation: An asynchronous operation to execute within the task. The operation |
30 |
| - /// inherits the current actor context and is isolated to that actor. |
31 |
| - /// - Returns: A `Task` object that wraps the result of the operation. |
32 |
| - func task<Success: Sendable>( |
33 |
| - priority: TaskPriority?, |
34 |
| - @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success |
35 |
| - ) -> Task<Success, Never> |
| 12 | + // swiftlint:disable attributes |
| 13 | + /// A protocol for creating and managing tasks with different configurations. |
| 14 | + /// Provides methods to create tasks tied to the current actor context or detached tasks |
| 15 | + /// that run independently of the current actor. |
| 16 | + public protocol ITaskFactory { |
| 17 | + /// Creates a task tied to the current actor context that can throw errors. |
| 18 | + /// - Parameters: |
| 19 | + /// - priority: The priority of the task (optional). |
| 20 | + /// - operation: An asynchronous operation to execute within the task. The operation |
| 21 | + /// inherits the current actor context and is isolated to that actor. |
| 22 | + /// - Returns: A `Task` object that wraps the result or error of the operation. |
| 23 | + func task<Success: Sendable>( |
| 24 | + priority: TaskPriority?, |
| 25 | + @_inheritActorContext operation: sending @escaping @isolated(any) () async throws -> Success |
| 26 | + ) -> Task<Success, Error> |
36 | 27 |
|
37 |
| - /// Creates a detached task that runs independently of the current actor context |
38 |
| - /// and can throw errors. |
39 |
| - /// - Parameters: |
40 |
| - /// - priority: The priority of the task (optional). |
41 |
| - /// - operation: An asynchronous operation to execute within the task. The operation |
42 |
| - /// is isolated and does not inherit the current actor context. |
43 |
| - /// - Returns: A `Task` object that wraps the result or error of the operation. |
44 |
| - func detached<Success: Sendable>( |
45 |
| - priority: TaskPriority?, |
46 |
| - @_inheritActorContext operation: sending @escaping @isolated(any) () async throws -> Success |
47 |
| - ) -> Task<Success, Error> |
| 28 | + /// Creates a task tied to the current actor context that does not throw errors. |
| 29 | + /// - Parameters: |
| 30 | + /// - priority: The priority of the task (optional). |
| 31 | + /// - operation: An asynchronous operation to execute within the task. The operation |
| 32 | + /// inherits the current actor context and is isolated to that actor. |
| 33 | + /// - Returns: A `Task` object that wraps the result of the operation. |
| 34 | + func task<Success: Sendable>( |
| 35 | + priority: TaskPriority?, |
| 36 | + @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success |
| 37 | + ) -> Task<Success, Never> |
48 | 38 |
|
49 |
| - /// Creates a detached task that runs independently of the current actor context |
50 |
| - /// and does not throw errors. |
51 |
| - /// - Parameters: |
52 |
| - /// - priority: The priority of the task (optional). |
53 |
| - /// - operation: An asynchronous operation to execute within the task. The operation |
54 |
| - /// is isolated and does not inherit the current actor context. |
55 |
| - /// - Returns: A `Task` object that wraps the result of the operation. |
56 |
| - func detached<Success: Sendable>( |
57 |
| - priority: TaskPriority?, |
58 |
| - @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success |
59 |
| - ) -> Task<Success, Never> |
60 |
| -} |
| 39 | + /// Creates a detached task that runs independently of the current actor context |
| 40 | + /// and can throw errors. |
| 41 | + /// - Parameters: |
| 42 | + /// - priority: The priority of the task (optional). |
| 43 | + /// - operation: An asynchronous operation to execute within the task. The operation |
| 44 | + /// is isolated and does not inherit the current actor context. |
| 45 | + /// - Returns: A `Task` object that wraps the result or error of the operation. |
| 46 | + func detached<Success: Sendable>( |
| 47 | + priority: TaskPriority?, |
| 48 | + @_inheritActorContext operation: sending @escaping @isolated(any) () async throws -> Success |
| 49 | + ) -> Task<Success, Error> |
61 | 50 |
|
62 |
| -/// Default implementations for the `ITaskFactory` protocol. |
63 |
| -public extension ITaskFactory { |
64 |
| - /// Creates a task tied to the current actor context with a default priority |
65 |
| - /// that can throw errors. |
66 |
| - /// - Parameter operation: An asynchronous operation to execute within the task. |
67 |
| - /// - Returns: A `Task` object that wraps the result or error of the operation. |
68 |
| - func task<Success: Sendable>( |
69 |
| - @_inheritActorContext operation: sending @escaping @isolated(any) () async throws -> Success |
70 |
| - ) -> Task<Success, Error> { |
71 |
| - task(priority: nil, operation: operation) |
| 51 | + /// Creates a detached task that runs independently of the current actor context |
| 52 | + /// and does not throw errors. |
| 53 | + /// - Parameters: |
| 54 | + /// - priority: The priority of the task (optional). |
| 55 | + /// - operation: An asynchronous operation to execute within the task. The operation |
| 56 | + /// is isolated and does not inherit the current actor context. |
| 57 | + /// - Returns: A `Task` object that wraps the result of the operation. |
| 58 | + func detached<Success: Sendable>( |
| 59 | + priority: TaskPriority?, |
| 60 | + @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success |
| 61 | + ) -> Task<Success, Never> |
72 | 62 | }
|
73 | 63 |
|
74 |
| - /// Creates a task tied to the current actor context with a default priority |
75 |
| - /// that does not throw errors. |
76 |
| - /// - Parameter operation: An asynchronous operation to execute within the task. |
77 |
| - /// - Returns: A `Task` object that wraps the result of the operation. |
78 |
| - func task<Success: Sendable>( |
79 |
| - @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success |
80 |
| - ) -> Task<Success, Never> { |
81 |
| - task(priority: nil, operation: operation) |
82 |
| - } |
| 64 | + /// Default implementations for the `ITaskFactory` protocol. |
| 65 | + public extension ITaskFactory { |
| 66 | + /// Creates a task tied to the current actor context with a default priority |
| 67 | + /// that can throw errors. |
| 68 | + /// - Parameter operation: An asynchronous operation to execute within the task. |
| 69 | + /// - Returns: A `Task` object that wraps the result or error of the operation. |
| 70 | + func task<Success: Sendable>( |
| 71 | + @_inheritActorContext operation: sending @escaping @isolated(any) () async throws -> Success |
| 72 | + ) -> Task<Success, Error> { |
| 73 | + task(priority: nil, operation: operation) |
| 74 | + } |
83 | 75 |
|
84 |
| - /// Creates a detached task with a default priority that runs independently |
85 |
| - /// of the current actor context and can throw errors. |
86 |
| - /// - Parameter operation: An asynchronous operation to execute within the task. |
87 |
| - /// - Returns: A `Task` object that wraps the result or error of the operation. |
88 |
| - func detached<Success: Sendable>( |
89 |
| - @_inheritActorContext operation: sending @escaping @isolated(any) () async throws -> Success |
90 |
| - ) -> Task<Success, Error> { |
91 |
| - detached(priority: nil, operation: operation) |
92 |
| - } |
| 76 | + /// Creates a task tied to the current actor context with a default priority |
| 77 | + /// that does not throw errors. |
| 78 | + /// - Parameter operation: An asynchronous operation to execute within the task. |
| 79 | + /// - Returns: A `Task` object that wraps the result of the operation. |
| 80 | + func task<Success: Sendable>( |
| 81 | + @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success |
| 82 | + ) -> Task<Success, Never> { |
| 83 | + task(priority: nil, operation: operation) |
| 84 | + } |
| 85 | + |
| 86 | + /// Creates a detached task with a default priority that runs independently |
| 87 | + /// of the current actor context and can throw errors. |
| 88 | + /// - Parameter operation: An asynchronous operation to execute within the task. |
| 89 | + /// - Returns: A `Task` object that wraps the result or error of the operation. |
| 90 | + func detached<Success: Sendable>( |
| 91 | + @_inheritActorContext operation: sending @escaping @isolated(any) () async throws -> Success |
| 92 | + ) -> Task<Success, Error> { |
| 93 | + detached(priority: nil, operation: operation) |
| 94 | + } |
93 | 95 |
|
94 |
| - /// Creates a detached task with a default priority that runs independently |
95 |
| - /// of the current actor context and does not throw errors. |
96 |
| - /// - Parameter operation: An asynchronous operation to execute within the task. |
97 |
| - /// - Returns: A `Task` object that wraps the result of the operation. |
98 |
| - func detached<Success: Sendable>( |
99 |
| - @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success |
100 |
| - ) -> Task<Success, Never> { |
101 |
| - detached(priority: nil, operation: operation) |
| 96 | + /// Creates a detached task with a default priority that runs independently |
| 97 | + /// of the current actor context and does not throw errors. |
| 98 | + /// - Parameter operation: An asynchronous operation to execute within the task. |
| 99 | + /// - Returns: A `Task` object that wraps the result of the operation. |
| 100 | + func detached<Success: Sendable>( |
| 101 | + @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success |
| 102 | + ) -> Task<Success, Never> { |
| 103 | + detached(priority: nil, operation: operation) |
| 104 | + } |
102 | 105 | }
|
103 |
| -} |
104 | 106 |
|
105 |
| -// swiftlint:enable attributes |
| 107 | + // swiftlint:enable attributes |
| 108 | +#endif |
0 commit comments