Skip to content

Commit d6adac3

Browse files
committed
[Concurrency] Stubs for Task.current()
1 parent 07f80be commit d6adac3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ import Swift
2828
public struct Task {
2929
}
3030

31+
// ==== Current Task -----------------------------------------------------------
32+
33+
extension Task {
34+
/// Returns the currently executing `Task`.
35+
///
36+
/// As invoking this function is only possible from an asynchronous context
37+
/// it is always able to return the current `Task` in which we are currently
38+
/// running.
39+
public static func current() async -> Task {
40+
fatalError("\(#function) not implemented yet.")
41+
}
42+
}
43+
3144
// ==== Task Priority ----------------------------------------------------------
3245

3346
extension Task {

test/Concurrency/async_tasks.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,13 @@ func test_detached_throwing() async -> String {
6262
print("caught: \(error)")
6363
}
6464
}
65+
66+
// ==== Current Task -----------------------------------------------------------
67+
68+
func test_current_task() async {
69+
let task = await Task.current() // yay, we know "in" what task we're executing
70+
}
71+
72+
func test_current_task_notasync() {
73+
let task = Task.current()
74+
}

0 commit comments

Comments
 (0)