carlhung
(Carlhung)
1
I tested the code on Linux:
protocol Pro1 {
func foo() async
}
protocol Pro2: Pro1 {
@MainActor
func foo() async
}
struct ST: Pro2 {
func foo() {
print("isMainThread: \(Thread.isMainThread)")
}
}
let s = ST()
Task.detached {
await s.foo()
}
Task {
await s.foo()
}
dispatchMain()
It printed out:
isMainThread: false
isMainThread: false
I was expecting both to be true.
Did I do anything wrong?
1 Like