File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,19 @@ import Swift
28
28
public struct Task {
29
29
}
30
30
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
+
31
44
// ==== Task Priority ----------------------------------------------------------
32
45
33
46
extension Task {
Original file line number Diff line number Diff line change @@ -62,3 +62,13 @@ func test_detached_throwing() async -> String {
62
62
print ( " caught: \( error) " )
63
63
}
64
64
}
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
+ }
You can’t perform that action at this time.
0 commit comments