Skip to content

Commit 70a6c3b

Browse files
committed
cleanups
1 parent d5caa48 commit 70a6c3b

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

stdlib/public/Concurrency/Task+TaskExecutor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ extension Task where Failure == Never {
332332
/// Runs the given nonthrowing operation asynchronously
333333
/// as part of a new top-level task.
334334
///
335-
/// Don't use a detached task if it's possible
335+
/// Don't use a detached unstructured task if it's possible
336336
/// to model the operation using structured concurrency features like child tasks.
337337
/// Child tasks inherit the parent task's priority and task-local storage,
338338
/// and canceling a parent task automatically cancels all of its child tasks.
@@ -393,7 +393,7 @@ extension Task where Failure == Error {
393393
///
394394
/// If the operation throws an error, this method propagates that error.
395395
///
396-
/// Don't use a detached task if it's possible
396+
/// Don't use a detached unstructured task if it's possible
397397
/// to model the operation using structured concurrency features like child tasks.
398398
/// Child tasks inherit the parent task's priority and task-local storage,
399399
/// and canceling a parent task automatically cancels all of its child tasks.

stdlib/public/Concurrency/Task+init.swift.gyb

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ import Swift
7676
% ARROW_RETURN_TYPE = '' # init does not spell out return type
7777
% end
7878

79+
% if IS_DETACHED:
80+
% THE_FUNC = 'public static func detached'
81+
% else:
82+
% THE_FUNC = 'public init'
83+
% end
84+
7985
% # ====================================================================================================================
8086
@available(SwiftStdlib 5.1, *)
8187
extension Task where Failure == ${FAILURE_TYPE} {
@@ -85,11 +91,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
8591
@discardableResult
8692
@_alwaysEmitIntoClient
8793
@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}(
9395
${",\n ".join(adjust_params_for_kind(PARAMS))}
9496
) ${ARROW_RETURN_TYPE}{
9597
fatalError("Unavailable in task-to-thread concurrency model.")
@@ -100,11 +102,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
100102
@discardableResult
101103
@_alwaysEmitIntoClient
102104
@available(SwiftStdlib 5.1, *)
103-
% if IS_DETACHED:
104-
public static func detached(
105-
% else:
106-
public init(
107-
% end
105+
${THE_FUNC}(
108106
${",\n ".join(adjust_params_for_kind(PARAMS))}
109107
) ${ARROW_RETURN_TYPE}{
110108
// Set up the job flags for a new task.
@@ -126,36 +124,53 @@ extension Task where Failure == ${FAILURE_TYPE} {
126124

127125
% # --------------------------------------------------------------------------------------------------------------------
128126
#else
127+
% if IS_THROWING:
128+
/// Runs the given throwing operation asynchronously
129+
% else:
129130
/// 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
131143
///
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
133146
/// to model the operation using structured concurrency features like child tasks.
134147
/// Child tasks inherit the parent task's priority and task-local storage,
135148
/// and canceling a parent task automatically cancels all of its child tasks.
136149
/// You need to handle these considerations manually with a detached task.
150+
% end
137151
///
138-
/// You need to keep a reference to the detached task
152+
/// You need to keep a reference to the task
139153
/// 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
141155
/// doesn't implicitly cancel that task,
142156
/// it only makes it impossible for you to explicitly cancel the task.
143157
///
144158
/// - Parameters:
145159
% if HAS_TASK_NAME:
146160
/// - name: Human readable name of the task.
147161
% 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
148167
/// - priority: The priority of the task.
149168
/// - operation: The operation to perform.
150169
///
151170
/// - Returns: A reference to the task.
152171
${"\n ".join(ALL_AVAILABILITY)}
153172
@discardableResult
154-
% if IS_DETACHED:
155-
public static func detached(
156-
% else:
157-
public init(
158-
% end
173+
${THE_FUNC}(
159174
${",\n ".join(adjust_params_for_kind(PARAMS))}
160175
) ${ARROW_RETURN_TYPE}{
161176

stdlib/public/Concurrency/Task.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ extension Task where Failure == Never {
724724
/// Runs the given nonthrowing operation asynchronously
725725
/// as part of a new top-level task.
726726
///
727-
/// Don't use a detached task if it's possible
727+
/// Don't use a detached unstructured task if it's possible
728728
/// to model the operation using structured concurrency features like child tasks.
729729
/// Child tasks inherit the parent task's priority and task-local storage,
730730
/// and canceling a parent task automatically cancels all of its child tasks.
@@ -784,9 +784,11 @@ extension Task where Failure == Error {
784784
/// Runs the given throwing operation asynchronously
785785
/// as part of a new top-level task.
786786
///
787-
/// If the operation throws an error, this method propagates that error.
787+
/// If the `operation` throws an error, it is caught by the `Task` and will be
788+
/// rethrown only when the task's `value` is awaited. Take care to not accidentally
789+
/// dismiss errors by not awaiting on the task's resulting value.
788790
///
789-
/// Don't use a detached task if it's possible
791+
/// Don't use a detached unstructured task if it's possible
790792
/// to model the operation using structured concurrency features like child tasks.
791793
/// Child tasks inherit the parent task's priority and task-local storage,
792794
/// and canceling a parent task automatically cancels all of its child tasks.

0 commit comments

Comments
 (0)