Skip to content

Instantly share code, notes, and snippets.

@inamiy
Last active April 13, 2022 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inamiy/6ab294f7cc47d1f79b892740578a712a to your computer and use it in GitHub Desktop.
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
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