Skip to content

Commit 614c008

Browse files
committed
Revise doc comments for changes from the release branch.
1 parent f3c073d commit 614c008

File tree

1 file changed

+99
-32
lines changed

1 file changed

+99
-32
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 99 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ import Swift
5555
/// like the reason for cancellation.
5656
/// This reflects the fact that a task can be canceled for many reasons,
5757
/// and additional reasons can accrue during the cancellation process.
58-
/// For example,
59-
/// if it takes the task too long to exit after being canceled,
60-
/// it could also miss a deadline.
61-
/// ◊FIXME: Replace above example -- deadlines aren't part of the API yet
62-
/// Cancellation is a lightweight way to stop a task before it completes,
63-
/// not a general mechanism for inter-task communication.
6458
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
6559
public struct Task {
6660
internal let _task: Builtin.NativeObject
@@ -418,9 +412,8 @@ extension Task {
418412
}
419413
}
420414

421-
/// Whether this is a task created by the 'async' operation, which
422-
/// conceptually continues the work of the synchronous code that invokes
423-
/// it.
415+
/// Whether this is a task created by an asynchronous operation,
416+
/// continuing the work of the synchronous code that invokes it.
424417
var isContinuingAsyncTask: Bool {
425418
get {
426419
(bits & (1 << 27)) != 0
@@ -453,7 +446,8 @@ extension Task {
453446

454447
}
455448

456-
/// Run the given non-throwing operation as part of a new top-level task.
449+
/// Runs the given nonthrowing operation asynchronously
450+
/// as part of a new top-level task.
457451
///
458452
/// Avoid using a detached task unless it isn't possible
459453
/// to model the operation using structured concurrency features like child tasks.
@@ -493,7 +487,8 @@ public func detach<T>(
493487
return Task.Handle<T, Never>(task)
494488
}
495489

496-
/// Run given throwing `operation` as part of a new top-level task.
490+
/// Runs the given throwing operation asynchronously
491+
/// as part of a new top-level task.
497492
///
498493
/// If the operation throws an error, this method propogates that error.
499494
///
@@ -535,6 +530,26 @@ public func detach<T>(
535530
return Task.Handle<T, Error>(task)
536531
}
537532

533+
/// Runs the given nonthrowing operation asynchronously
534+
/// as part of a new top-level task.
535+
///
536+
/// Avoid using a detached task unless it isn't possible
537+
/// to model the operation using structured concurrency features like child tasks.
538+
/// Child tasks inherit the parent task's priority and task-local storage,
539+
/// and canceling a parent task automatically cancels all of its child tasks.
540+
/// You need to handle these considerations manually with a detached task.
541+
///
542+
/// A detached task runs to completion
543+
/// unless it is explicitly canceled by calling the `Task.Handle.cancel()` method.
544+
/// Specifically, dropping a detached task's handle
545+
/// doesn't cancel that task.
546+
///
547+
/// - Parameters:
548+
/// - priority: The priority of the task.
549+
/// - executor: The executor that the detached closure should start executing on.
550+
/// - operation: The operation to perform.
551+
///
552+
/// - Returns: A handle to the task.
538553
@discardableResult
539554
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
540555
public func asyncDetached<T>(
@@ -544,6 +559,28 @@ public func asyncDetached<T>(
544559
return detach(priority: priority ?? .unspecified, operation: operation)
545560
}
546561

562+
/// Runs the given throwing operation asynchronously
563+
/// as part of a new top-level task.
564+
///
565+
/// If the operation throws an error, this method propogates that error.
566+
///
567+
/// Avoid using a detached task unless it isn't possible
568+
/// to model the operation using structured concurrency features like child tasks.
569+
/// Child tasks inherit the parent task's priority and task-local storage,
570+
/// and canceling a parent task automatically cancels all of its child tasks.
571+
/// You need to handle these considerations manually with a detached task.
572+
///
573+
/// A detached task runs to completion
574+
/// unless it is explicitly canceled by calling the `Task.Handle.cancel()` method.
575+
/// Specifically, dropping a detached task's handle
576+
/// doesn't cancel that task.
577+
///
578+
/// - Parameters:
579+
/// - priority: The priority of the task.
580+
/// - executor: The executor that the detached closure should start executing on.
581+
/// - operation: The operation to perform.
582+
///
583+
/// - Returns: A handle to the task.
547584
@discardableResult
548585
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
549586
public func asyncDetached<T>(
@@ -553,7 +590,27 @@ public func asyncDetached<T>(
553590
return detach(priority: priority ?? .unspecified, operation: operation)
554591
}
555592

556-
/// ABI stub while we stage in the new signatures
593+
594+
// ABI stub while we stage in the new signatures
595+
/// Runs the given nonthrowing operation asynchronously
596+
/// as part of a new top-level task on behalf of the current actor.
597+
///
598+
/// Use this function when creating asynchronous work
599+
/// that operates on behalf of the synchronous function that calls it.
600+
/// Like `detach(priority:operation:)`,
601+
/// this function creates a separate, top-level task.
602+
/// Unlike `detach(priority:operation:)`,
603+
/// the task creating by `async(priority:operation:)`
604+
/// inherits the priority and actor context of the caller,
605+
/// so the operation is treated more like an asynchronous extension
606+
/// to the synchronous operation.
607+
///
608+
/// - Parameters:
609+
/// - priority: The priority of the task.
610+
/// Pass `nil` to use the priority from `Task.currentPriority`.
611+
/// - operation: The operation to perform.
612+
///
613+
/// - Returns: A handle to the task.
557614
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
558615
@usableFromInline
559616
func async(
@@ -569,20 +626,25 @@ func async(
569626
let _: Task.Handle = async(priority: adjustedPriority, operation: operation)
570627
}
571628

572-
/// Run given `operation` as asynchronously in its own top-level task.
629+
/// Runs the given nonthrowing operation asynchronously
630+
/// as part of a new top-level task on behalf of the current actor.
573631
///
574-
/// The `async` function should be used when creating asynchronous work
632+
/// Use this function when creating asynchronous work
575633
/// that operates on behalf of the synchronous function that calls it.
576-
/// Like `detach`, the async function creates a separate, top-level task.
577-
/// Unlike `detach`, the task creating by `async` inherits the priority and
578-
/// actor context of the caller, so the `operation` is treated more like an
579-
/// asynchronous extension to the synchronous operation. Additionally, `async`
580-
/// does not return a handle to refer to the task.
634+
/// Like `detach(priority:operation:)`,
635+
/// this function creates a separate, top-level task.
636+
/// Unlike `detach(priority:operation:)`,
637+
/// the task creating by `async(priority:operation:)`
638+
/// inherits the priority and actor context of the caller,
639+
/// so the operation is treated more like an asynchronous extension
640+
/// to the synchronous operation.
581641
///
582642
/// - Parameters:
583-
/// - priority: priority of the task. If nil, the priority will come from
584-
/// Task.currentPriority.
585-
/// - operation: the operation to execute
643+
/// - priority: The priority of the task.
644+
/// Pass `nil` to use the priority from `Task.currentPriority`.
645+
/// - operation: The operation to perform.
646+
///
647+
/// - Returns: A handle to the task.
586648
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
587649
@discardableResult
588650
public func async<T>(
@@ -605,20 +667,25 @@ public func async<T>(
605667
return Task.Handle(task)
606668
}
607669

608-
/// Run given `operation` as asynchronously in its own top-level task.
670+
/// Runs the given throwing operation asynchronously
671+
/// as part of a new top-level task on behalf of the current actor.
609672
///
610-
/// The `async` function should be used when creating asynchronous work
673+
/// Use this function when creating asynchronous work
611674
/// that operates on behalf of the synchronous function that calls it.
612-
/// Like `detach`, the async function creates a separate, top-level task.
613-
/// Unlike `detach`, the task creating by `async` inherits the priority and
614-
/// actor context of the caller, so the `operation` is treated more like an
615-
/// asynchronous extension to the synchronous operation. Additionally, `async`
616-
/// does not return a handle to refer to the task.
675+
/// Like `detach(priority:operation:)`,
676+
/// this function creates a separate, top-level task.
677+
/// Unlike `detach(priority:operation:)`,
678+
/// the task creating by `async(priority:operation:)`
679+
/// inherits the priority and actor context of the caller,
680+
/// so the operation is treated more like an asynchronous extension
681+
/// to the synchronous operation.
617682
///
618683
/// - Parameters:
619-
/// - priority: priority of the task. If nil, the priority will come from
620-
/// Task.currentPriority.
621-
/// - operation: the operation to execute
684+
/// - priority: The priority of the task.
685+
/// Pass `nil` to use the priority from `Task.currentPriority`.
686+
/// - operation: The operation to perform.
687+
///
688+
/// - Returns: A handle to the task.
622689
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
623690
@discardableResult
624691
public func async<T>(

0 commit comments

Comments
 (0)