Avatar
omochimetaru 3/3/2022 11:24 AM
@swift-5.5.3 -Xfrontend -parse-as-library import Foundation @globalActor actor OtherActor { static let shared = OtherActor() static func run(_ body: @OtherActor () async -> Void) async { @OtherActor func inner() async { await body() } await inner() } } @main struct Entrypoint { static func main() async throws { print(Thread.current, Thread.isMainThread) await OtherActor.run { let _: () = await withUnsafeContinuation { c in test1 { print("t1", Thread.current, Thread.isMainThread) c.resume(returning: ()) } } let _: () = await withUnsafeContinuation { c in test1 { @MainActor () in print("t2", Thread.current, Thread.isMainThread) assumeMainActor() c.resume(returning: ()) } } } } } private func test1(_ f: @MainActor @escaping () async -> Void) { Task.detached { await f() } } private func test2(_ f: @escaping () async -> Void) { test1(f) } @MainActor func assumeMainActor() { print("Here must be MainActor! but Thread.isMainThread = \(Thread.isMainThread)") }