Skip to content

Commit 6aefea0

Browse files
committed
Fix up some documentation for the async/detach renamings
1 parent fdee0ff commit 6aefea0

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
@@ -18,7 +18,7 @@ import Swift
1818
/// An asynchronous task (just "Task" hereafter) is the analogue of a thread for
1919
/// asynchronous functions. All asynchronous functions run as part of some task.
2020
///
21-
/// An instance of `Task` always represents a "detached" task. The instance
21+
/// An instance of `Task` always represents a top-level task. The instance
2222
/// can be used to await its completion, cancel the task, etc., The task will
2323
/// run to completion even if there are no other instances of the `Task`.
2424
///
@@ -149,7 +149,7 @@ extension Task: Equatable {
149149
/// ### Priority inheritance
150150
/// Child tasks automatically inherit their parent task's priority.
151151
///
152-
/// Detached tasks (created by `detach`) DO NOT inherit task priority,
152+
/// Detached tasks (created by `Task.detached`) DO NOT inherit task priority,
153153
/// as they are "detached" from their parent tasks after all.
154154
///
155155
/// ### Priority elevation
@@ -368,11 +368,13 @@ extension Task where Failure == Never {
368368
///
369369
/// The `async` function should be used when creating asynchronous work
370370
/// that operates on behalf of the synchronous function that calls it.
371-
/// Like `detach`, the async function creates a separate, top-level task.
372-
/// Unlike `detach`, the task creating by `async` inherits the priority and
373-
/// actor context of the caller, so the `operation` is treated more like an
374-
/// asynchronous extension to the synchronous operation. Additionally, `async`
375-
/// does not return a handle to refer to the task.
371+
/// Like `Task.detached`, the async function creates a separate, top-level
372+
/// task.
373+
///
374+
/// Unlike `Task.detached`, the task creating by the `Task` initializer
375+
/// inherits the priority and actor context of the caller, so the `operation`
376+
/// is treated more like an asynchronous extension to the synchronous
377+
/// operation.
376378
///
377379
/// - Parameters:
378380
/// - priority: priority of the task. If nil, the priority will come from
@@ -413,13 +415,11 @@ extension Task where Failure == Never {
413415
extension Task where Failure == Error {
414416
/// Run given `operation` as asynchronously in its own top-level task.
415417
///
416-
/// The `async` function should be used when creating asynchronous work
417-
/// that operates on behalf of the synchronous function that calls it.
418-
/// Like `detach`, the async function creates a separate, top-level task.
419-
/// Unlike `detach`, the task creating by `async` inherits the priority and
418+
/// This initializer creates asynchronous work on behalf of the synchronous function that calls it.
419+
/// Like `Task.detached`, this initializer creates a separate, top-level task.
420+
/// Unlike `Task.detached`, the task created inherits the priority and
420421
/// actor context of the caller, so the `operation` is treated more like an
421-
/// asynchronous extension to the synchronous operation. Additionally, `async`
422-
/// does not return a handle to refer to the task.
422+
/// asynchronous extension to the synchronous operation.
423423
///
424424
/// - Parameters:
425425
/// - priority: priority of the task. If nil, the priority will come from
@@ -472,10 +472,10 @@ extension Task where Failure == Never {
472472
///
473473
/// ### Cancellation
474474
/// A detached task always runs to completion unless it is explicitly cancelled.
475-
/// Specifically, dropping a detached tasks `Task.Handle` does _not_ automatically
475+
/// Specifically, dropping a detached tasks `Task` does _not_ automatically
476476
/// cancel given task.
477477
///
478-
/// Cancelling a task must be performed explicitly via `handle.cancel()`.
478+
/// Cancelling a task must be performed explicitly via `cancel()`.
479479
///
480480
/// - Note: it is generally preferable to use child tasks rather than detached
481481
/// tasks. Child tasks automatically carry priorities, task-local state,
@@ -485,10 +485,8 @@ extension Task where Failure == Never {
485485
///
486486
/// - Parameters:
487487
/// - priority: priority of the task
488-
/// - executor: the executor on which the detached closure should start
489-
/// executing on.
490488
/// - operation: the operation to execute
491-
/// - Returns: handle to the task, allowing to `await handle.get()` on the
489+
/// - Returns: handle to the task, allowing to `await get()` on the
492490
/// tasks result or `cancel` it. If the operation fails the handle will
493491
/// throw the error the operation has thrown when awaited on.
494492
@discardableResult
@@ -720,7 +718,7 @@ public func _asyncMainDrainQueue() -> Never
720718
@available(SwiftStdlib 5.5, *)
721719
public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) {
722720
#if os(Windows)
723-
detach {
721+
Task.detached {
724722
do {
725723
try await asyncFun()
726724
exit(0)
@@ -738,7 +736,7 @@ public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) {
738736
}
739737
}
740738

741-
detach {
739+
Task.detached {
742740
await _doMain(asyncFun)
743741
exit(0)
744742
}

0 commit comments

Comments
 (0)