@@ -17,7 +17,7 @@ import Swift
17
17
18
18
/// A unit of asynchronous work.
19
19
///
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
21
21
/// can be used to await its completion, cancel the task, etc., The task will
22
22
/// run to completion even if there are no other instances of the `Task`.
23
23
///
@@ -177,7 +177,7 @@ extension Task: Equatable {
177
177
/// ### Priority inheritance
178
178
/// Child tasks automatically inherit their parent task's priority.
179
179
///
180
- /// Detached tasks (created by `detach `) DO NOT inherit task priority,
180
+ /// Detached tasks (created by `Task.detached `) DO NOT inherit task priority,
181
181
/// as they are "detached" from their parent tasks after all.
182
182
///
183
183
/// ### Priority elevation
@@ -396,11 +396,13 @@ extension Task where Failure == Never {
396
396
///
397
397
/// The `async` function should be used when creating asynchronous work
398
398
/// 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.
404
406
///
405
407
/// - Parameters:
406
408
/// - priority: priority of the task. If nil, the priority will come from
@@ -441,13 +443,11 @@ extension Task where Failure == Never {
441
443
extension Task where Failure == Error {
442
444
/// Run given `operation` as asynchronously in its own top-level task.
443
445
///
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
448
449
/// 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.
451
451
///
452
452
/// - Parameters:
453
453
/// - priority: priority of the task. If nil, the priority will come from
@@ -500,10 +500,10 @@ extension Task where Failure == Never {
500
500
///
501
501
/// ### Cancellation
502
502
/// 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
504
504
/// cancel given task.
505
505
///
506
- /// Cancelling a task must be performed explicitly via `handle. cancel()`.
506
+ /// Cancelling a task must be performed explicitly via `cancel()`.
507
507
///
508
508
/// - Note: it is generally preferable to use child tasks rather than detached
509
509
/// tasks. Child tasks automatically carry priorities, task-local state,
@@ -513,10 +513,8 @@ extension Task where Failure == Never {
513
513
///
514
514
/// - Parameters:
515
515
/// - priority: priority of the task
516
- /// - executor: the executor on which the detached closure should start
517
- /// executing on.
518
516
/// - 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
520
518
/// tasks result or `cancel` it. If the operation fails the handle will
521
519
/// throw the error the operation has thrown when awaited on.
522
520
@discardableResult
@@ -784,7 +782,7 @@ public func _asyncMainDrainQueue() -> Never
784
782
@available ( SwiftStdlib 5 . 5 , * )
785
783
public func _runAsyncMain( _ asyncFun: @escaping ( ) async throws -> ( ) ) {
786
784
#if os(Windows)
787
- detach {
785
+ Task . detached {
788
786
do {
789
787
try await asyncFun ( )
790
788
exit ( 0 )
@@ -802,7 +800,7 @@ public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) {
802
800
}
803
801
}
804
802
805
- detach {
803
+ Task . detached {
806
804
await _doMain ( asyncFun)
807
805
exit ( 0 )
808
806
}
0 commit comments