Last active
April 13, 2022 03:05
-
-
Save inamiy/6ab294f7cc47d1f79b892740578a712a to your computer and use it in GitHub Desktop.
Swift 5.5 Actor impl with stealing GlobalActor's Executors https://twitter.com/inamiy/status/1514076289443176453
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import _Concurrency | |
actor SomeSystem { | |
nonisolated var unownedExecutor: UnownedSerialExecutor { | |
#if os(Linux) | |
MyActor.sharedUnownedExecutor | |
#else | |
MainActor.sharedUnownedExecutor | |
#endif | |
} | |
func hello() { | |
print(Thread.current) // main thread | |
} | |
} | |
@globalActor | |
actor MyActor { | |
static let shared = MyActor() | |
} | |
Task { | |
let system = SomeSystem() | |
await system.hello() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment