Skip to content

Commit 12c3eb2

Browse files
committed
Verify that main is running on main thread
This patch adds a check to verify that we're running on the main thread when running the async-main function.
1 parent a643fe4 commit 12c3eb2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

test/Concurrency/Runtime/mainactor.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ actor A {
6666

6767
// CHECK: starting
6868
// CHECK-NOT: ERROR
69+
// CHECK: Hello from the main function
70+
// CHECK-NOT: ERROR
6971
// CHECK: hello from main actor!
7072
// CHECK-NOT: ERROR
7173
// CHECK: on actor instance's queue
@@ -77,6 +79,11 @@ actor A {
7779
@main struct RunIt {
7880
static func main() async {
7981
print("starting")
82+
if checkIfMainQueue(expectedAnswer: true) {
83+
print("Hello from the main function")
84+
} else {
85+
print("ERROR: not on the main queue")
86+
}
8087
let result = await someFunc()
8188
print("finished with return counter = \(result)")
8289
}

0 commit comments

Comments
 (0)