Skip to content

Commit 2a23b23

Browse files
committed
Fix up some documentation for the async/detach renamings
(cherry picked from commit 6aefea0)
1 parent 39180ad commit 2a23b23

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Swift
1717

1818
/// A unit of asynchronous work.
1919
///
20-
/// An instance of `Task` always represents a "detached" task. The instance
20+
/// An instance of `Task` always represents a top-level task. The instance
2121
/// can be used to await its completion, cancel the task, etc., The task will
2222
/// run to completion even if there are no other instances of the `Task`.
2323
///
@@ -177,7 +177,7 @@ extension Task: Equatable {
177177
/// ### Priority inheritance
178178
/// Child tasks automatically inherit their parent task's priority.
179179
///
180-
/// Detached tasks (created by `detach`) DO NOT inherit task priority,
180+
/// Detached tasks (created by `Task.detached`) DO NOT inherit task priority,
181181
/// as they are "detached" from their parent tasks after all.
182182
///
183183
/// ### Priority elevation
@@ -396,11 +396,13 @@ extension Task where Failure == Never {
396396
///
397397
/// The `async` function should be used when creating asynchronous work
398398
/// that operates on behalf of the synchronous function that calls it.
399-
/// Like `detach`, the async function creates a separate, top-level task.
400-
/// Unlike `detach`, the task creating by `async` inherits the priority and
401-
/// actor context of the caller, so the `operation` is treated more like an
402-
/// asynchronous extension to the synchronous operation. Additionally, `async`
403-
/// does not return a handle to refer to the task.
399+
/// Like `Task.detached`, the async function creates a separate, top-level
400+
/// task.
401+
///
402+
/// Unlike `Task.detached`, the task creating by the `Task` initializer
403+
/// inherits the priority and actor context of the caller, so the `operation`
404+
/// is treated more like an asynchronous extension to the synchronous
405+
/// operation.
404406
///
405407
/// - Parameters:
406408
/// - priority: priority of the task. If nil, the priority will come from
@@ -441,13 +443,11 @@ extension Task where Failure == Never {
441443
extension Task where Failure == Error {
442444
/// Run given `operation` as asynchronously in its own top-level task.
443445
///
444-
/// The `async` function should be used when creating asynchronous work
445-
/// that operates on behalf of the synchronous function that calls it.
446-
/// Like `detach`, the async function creates a separate, top-level task.
447-
/// Unlike `detach`, the task creating by `async` inherits the priority and
446+
/// This initializer creates asynchronous work on behalf of the synchronous function that calls it.
447+
/// Like `Task.detached`, this initializer creates a separate, top-level task.
448+
/// Unlike `Task.detached`, the task created inherits the priority and
448449
/// actor context of the caller, so the `operation` is treated more like an
449-
/// asynchronous extension to the synchronous operation. Additionally, `async`
450-
/// does not return a handle to refer to the task.
450+
/// asynchronous extension to the synchronous operation.
451451
///
452452
/// - Parameters:
453453
/// - priority: priority of the task. If nil, the priority will come from
@@ -500,10 +500,10 @@ extension Task where Failure == Never {
500500
///
501501
/// ### Cancellation
502502
/// A detached task always runs to completion unless it is explicitly cancelled.
503-
/// Specifically, dropping a detached tasks `Task.Handle` does _not_ automatically
503+
/// Specifically, dropping a detached tasks `Task` does _not_ automatically
504504
/// cancel given task.
505505
///
506-
/// Cancelling a task must be performed explicitly via `handle.cancel()`.
506+
/// Cancelling a task must be performed explicitly via `cancel()`.
507507
///
508508
/// - Note: it is generally preferable to use child tasks rather than detached
509509
/// tasks. Child tasks automatically carry priorities, task-local state,
@@ -513,10 +513,8 @@ extension Task where Failure == Never {
513513
///
514514
/// - Parameters:
515515
/// - priority: priority of the task
516-
/// - executor: the executor on which the detached closure should start
517-
/// executing on.
518516
/// - operation: the operation to execute
519-
/// - Returns: handle to the task, allowing to `await handle.get()` on the
517+
/// - Returns: handle to the task, allowing to `await get()` on the
520518
/// tasks result or `cancel` it. If the operation fails the handle will
521519
/// throw the error the operation has thrown when awaited on.
522520
@discardableResult
@@ -784,7 +782,7 @@ public func _asyncMainDrainQueue() -> Never
784782
@available(SwiftStdlib 5.5, *)
785783
public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) {
786784
#if os(Windows)
787-
detach {
785+
Task.detached {
788786
do {
789787
try await asyncFun()
790788
exit(0)
@@ -802,7 +800,7 @@ public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) {
802800
}
803801
}
804802

805-
detach {
803+
Task.detached {
806804
await _doMain(asyncFun)
807805
exit(0)
808806
}

0 commit comments

Comments
 (0)