@@ -18,7 +18,7 @@ import Swift
18
18
/// An asynchronous task (just "Task" hereafter) is the analogue of a thread for
19
19
/// asynchronous functions. All asynchronous functions run as part of some task.
20
20
///
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
22
22
/// can be used to await its completion, cancel the task, etc., The task will
23
23
/// run to completion even if there are no other instances of the `Task`.
24
24
///
@@ -149,7 +149,7 @@ extension Task: Equatable {
149
149
/// ### Priority inheritance
150
150
/// Child tasks automatically inherit their parent task's priority.
151
151
///
152
- /// Detached tasks (created by `detach `) DO NOT inherit task priority,
152
+ /// Detached tasks (created by `Task.detached `) DO NOT inherit task priority,
153
153
/// as they are "detached" from their parent tasks after all.
154
154
///
155
155
/// ### Priority elevation
@@ -368,11 +368,13 @@ extension Task where Failure == Never {
368
368
///
369
369
/// The `async` function should be used when creating asynchronous work
370
370
/// 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.
376
378
///
377
379
/// - Parameters:
378
380
/// - priority: priority of the task. If nil, the priority will come from
@@ -413,13 +415,11 @@ extension Task where Failure == Never {
413
415
extension Task where Failure == Error {
414
416
/// Run given `operation` as asynchronously in its own top-level task.
415
417
///
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
420
421
/// 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.
423
423
///
424
424
/// - Parameters:
425
425
/// - priority: priority of the task. If nil, the priority will come from
@@ -472,10 +472,10 @@ extension Task where Failure == Never {
472
472
///
473
473
/// ### Cancellation
474
474
/// 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
476
476
/// cancel given task.
477
477
///
478
- /// Cancelling a task must be performed explicitly via `handle. cancel()`.
478
+ /// Cancelling a task must be performed explicitly via `cancel()`.
479
479
///
480
480
/// - Note: it is generally preferable to use child tasks rather than detached
481
481
/// tasks. Child tasks automatically carry priorities, task-local state,
@@ -485,10 +485,8 @@ extension Task where Failure == Never {
485
485
///
486
486
/// - Parameters:
487
487
/// - priority: priority of the task
488
- /// - executor: the executor on which the detached closure should start
489
- /// executing on.
490
488
/// - 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
492
490
/// tasks result or `cancel` it. If the operation fails the handle will
493
491
/// throw the error the operation has thrown when awaited on.
494
492
@discardableResult
@@ -720,7 +718,7 @@ public func _asyncMainDrainQueue() -> Never
720
718
@available ( SwiftStdlib 5 . 5 , * )
721
719
public func _runAsyncMain( _ asyncFun: @escaping ( ) async throws -> ( ) ) {
722
720
#if os(Windows)
723
- detach {
721
+ Task . detached {
724
722
do {
725
723
try await asyncFun ( )
726
724
exit ( 0 )
@@ -738,7 +736,7 @@ public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) {
738
736
}
739
737
}
740
738
741
- detach {
739
+ Task . detached {
742
740
await _doMain ( asyncFun)
743
741
exit ( 0 )
744
742
}
0 commit comments