From d1443e9bd8020488c11db98964ffa38c0af886e6 Mon Sep 17 00:00:00 2001 From: Harjas Monga Date: Tue, 19 Nov 2024 10:46:45 -0800 Subject: [PATCH] Revert "refine API specifications" This reverts commit 53231c7fc5dc461a06ffd063b2539da66a0c7399. --- proposals/0454-task-naming-api.md | 42 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/proposals/0454-task-naming-api.md b/proposals/0454-task-naming-api.md index 7bbe768fc4..2f33ae9335 100644 --- a/proposals/0454-task-naming-api.md +++ b/proposals/0454-task-naming-api.md @@ -48,22 +48,21 @@ By introducing this in a structured, coherent way in Swift itself, rather than d ## Detailed design + Naming tasks is only allowed during their creation, and modifying names is not allowed. Names are arbitrary user-defined strings, which may be computed at runtime because they often contain identifying information such as the request ID or similar runtime information. In order to allow naming tasks, the following APIs will be provided on `Task`: ```swift -init( - name: String? = nil, - executorPreference taskExecutor: (any TaskExecutor)? = nil, - operation: sending @escaping @isolated(any) () async -> Success -) - -static func detached( - name: String? = nil, - executorPreference taskExecutor: (any TaskExecutor)? = nil, - operation: sending @escaping @isolated(any) () async -> Success -) + init( + name: String? = nil, + priority: TaskPriority? = nil, + operation: sending @escaping @isolated(any) () async -> Success + + static func detached( + name: String? = nil, + priority: TaskPriority? = nil, + operation: sending @escaping @isolated(any) () async -> Success ``` In addition to these APIs to name unstructured Tasks, the following API will be added to name Tasks created as a part of a task group task group: @@ -74,14 +73,15 @@ mutating func addTask( executorPreference taskExecutor: (any TaskExecutor)? = nil, priority: TaskPriority? = nil, operation: sending @escaping @isolated(any) () async -> ChildTaskResult -) + ) -mutating func addTaskUnlessCancelled( - name: String? = nil, - executorPreference taskExecutor: (any TaskExecutor)? = nil, - priority: TaskPriority? = nil, - operation: sending @escaping @isolated(any) () async -> ChildTaskResult -) + mutating func addTaskUnlessCancelled( + name: String? = nil, + executorPreference taskExecutor: (any TaskExecutor)? = nil, + priority: TaskPriority? = nil, + operation: sending @escaping @isolated(any) () async -> ChildTaskResult + ) + ``` These APIs would be added to all kinds of task groups, including throwing, discarding ones. With the signature being appropriately matching the existing addTask signatures of those groups @@ -90,11 +90,7 @@ In addition to that, it will be possible to read a name off a task, similar to h ```swift extension Task { - // read the name of a task instance, e.g. someTask.name - var name: String? { get } - - // read the name of the current task, e.g. Task.name - static var currentName: String? { get } + var currentName: String? { get } } ```