Skip to content

Commit 53231c7

Browse files
committed
refine API specifications
1 parent c0e0748 commit 53231c7

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

proposals/0454-task-naming-api.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,22 @@ By introducing this in a structured, coherent way in Swift itself, rather than d
4848

4949
## Detailed design
5050

51-
5251
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.
5352

5453
In order to allow naming tasks, the following APIs will be provided on `Task`:
5554

5655
```swift
57-
init(
58-
name: String? = nil,
59-
priority: TaskPriority? = nil,
60-
operation: sending @escaping @isolated(any) () async -> Success
61-
62-
static func detached(
63-
name: String? = nil,
64-
priority: TaskPriority? = nil,
65-
operation: sending @escaping @isolated(any) () async -> Success
56+
init(
57+
name: String? = nil,
58+
executorPreference taskExecutor: (any TaskExecutor)? = nil,
59+
operation: sending @escaping @isolated(any) () async -> Success
60+
)
61+
62+
static func detached(
63+
name: String? = nil,
64+
executorPreference taskExecutor: (any TaskExecutor)? = nil,
65+
operation: sending @escaping @isolated(any) () async -> Success
66+
)
6667
```
6768

6869
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:
@@ -73,15 +74,14 @@ mutating func addTask(
7374
executorPreference taskExecutor: (any TaskExecutor)? = nil,
7475
priority: TaskPriority? = nil,
7576
operation: sending @escaping @isolated(any) () async -> ChildTaskResult
76-
)
77+
)
7778

78-
mutating func addTaskUnlessCancelled(
79-
name: String? = nil,
80-
executorPreference taskExecutor: (any TaskExecutor)? = nil,
81-
priority: TaskPriority? = nil,
82-
operation: sending @escaping @isolated(any) () async -> ChildTaskResult
83-
)
84-
79+
mutating func addTaskUnlessCancelled(
80+
name: String? = nil,
81+
executorPreference taskExecutor: (any TaskExecutor)? = nil,
82+
priority: TaskPriority? = nil,
83+
operation: sending @escaping @isolated(any) () async -> ChildTaskResult
84+
)
8585
```
8686

8787
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,7 +90,11 @@ In addition to that, it will be possible to read a name off a task, similar to h
9090

9191
```swift
9292
extension Task {
93-
var currentName: String? { get }
93+
// read the name of a task instance, e.g. someTask.name
94+
var name: String? { get }
95+
96+
// read the name of the current task, e.g. Task.name
97+
static var currentName: String? { get }
9498
}
9599
```
96100

0 commit comments

Comments
 (0)