@@ -76,6 +76,12 @@ import Swift
76
76
% ARROW_RETURN_TYPE = '' # init does not spell out return type
77
77
% end
78
78
79
+ % if IS_DETACHED:
80
+ % THE_FUNC = 'public static func detached'
81
+ % else:
82
+ % THE_FUNC = 'public init'
83
+ % end
84
+
79
85
% # ====================================================================================================================
80
86
@available(SwiftStdlib 5.1, *)
81
87
extension Task where Failure == ${FAILURE_TYPE} {
@@ -85,11 +91,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
85
91
@discardableResult
86
92
@_alwaysEmitIntoClient
87
93
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
88
- % if IS_DETACHED:
89
- public static func detached(
90
- % else:
91
- public init(
92
- % end
94
+ ${THE_FUNC}(
93
95
${",\n ".join(adjust_params_for_kind(PARAMS))}
94
96
) ${ARROW_RETURN_TYPE}{
95
97
fatalError("Unavailable in task-to-thread concurrency model.")
@@ -100,11 +102,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
100
102
@discardableResult
101
103
@_alwaysEmitIntoClient
102
104
@available(SwiftStdlib 5.1, *)
103
- % if IS_DETACHED:
104
- public static func detached(
105
- % else:
106
- public init(
107
- % end
105
+ ${THE_FUNC}(
108
106
${",\n ".join(adjust_params_for_kind(PARAMS))}
109
107
) ${ARROW_RETURN_TYPE}{
110
108
// Set up the job flags for a new task.
@@ -126,36 +124,53 @@ extension Task where Failure == ${FAILURE_TYPE} {
126
124
127
125
% # --------------------------------------------------------------------------------------------------------------------
128
126
#else
127
+ % if IS_THROWING:
128
+ /// Runs the given throwing operation asynchronously
129
+ % else:
129
130
/// Runs the given nonthrowing operation asynchronously
130
- /// as part of a new top-level task.
131
+ % end
132
+ % if IS_DETACHED:
133
+ /// as part of a new _unstructured_ _detached_ top-level task.
134
+ % else:
135
+ /// as part of a new _unstructured_ top-level task.
136
+ % end
137
+ ///
138
+ % if IS_THROWING:
139
+ /// If the `operation` throws an error, it is caught by the `Task` and will be
140
+ /// rethrown only when the task's `value` is awaited. Take care to not accidentally
141
+ /// dismiss errors by not awaiting on the task's resulting value.
142
+ % end
131
143
///
132
- /// Don't use a detached task if it's possible
144
+ % if IS_DETACHED:
145
+ /// Don't use a detached unstructured task if it's possible
133
146
/// to model the operation using structured concurrency features like child tasks.
134
147
/// Child tasks inherit the parent task's priority and task-local storage,
135
148
/// and canceling a parent task automatically cancels all of its child tasks.
136
149
/// You need to handle these considerations manually with a detached task.
150
+ % end
137
151
///
138
- /// You need to keep a reference to the detached task
152
+ /// You need to keep a reference to the task
139
153
/// if you want to cancel it by calling the `Task.cancel()` method.
140
- /// Discarding your reference to a detached task
154
+ /// Discarding your reference to a task
141
155
/// doesn't implicitly cancel that task,
142
156
/// it only makes it impossible for you to explicitly cancel the task.
143
157
///
144
158
/// - Parameters:
145
159
% if HAS_TASK_NAME:
146
160
/// - name: Human readable name of the task.
147
161
% end
162
+ % if HAS_TASK_NAME:
163
+ /// - taskExecutor: the preferred task executor for this task,
164
+ /// and any child tasks created by it. Explicitly passing `nil` is
165
+ /// interpreted as "no preference".
166
+ % end
148
167
/// - priority: The priority of the task.
149
168
/// - operation: The operation to perform.
150
169
///
151
170
/// - Returns: A reference to the task.
152
171
${"\n ".join(ALL_AVAILABILITY)}
153
172
@discardableResult
154
- % if IS_DETACHED:
155
- public static func detached(
156
- % else:
157
- public init(
158
- % end
173
+ ${THE_FUNC}(
159
174
${",\n ".join(adjust_params_for_kind(PARAMS))}
160
175
) ${ARROW_RETURN_TYPE}{
161
176
0 commit comments