Skip to content

Commit

Permalink
Revert "refine API specifications"
Browse files Browse the repository at this point in the history
This reverts commit 53231c7.
  • Loading branch information
Harjas12 committed Nov 19, 2024
1 parent 53231c7 commit d1443e9
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions proposals/0454-task-naming-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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 }
}
```

Expand Down

0 comments on commit d1443e9

Please sign in to comment.