Add main actor trampolines

This commit is contained in:
Max Goedjen
2022-06-07 22:02:49 -07:00
parent 84dd9403c3
commit 0eab79c4c4
6 changed files with 26 additions and 5 deletions

View File

@@ -0,0 +1,17 @@
import Foundation
func mainActorWrapped(_ f: @escaping @MainActor () -> Void) -> () -> Void {
return {
DispatchQueue.main.async {
f()
}
}
}
func mainActorWrapped<T: Sendable>(_ f: @escaping @MainActor (T) -> Void) -> (T) -> Void {
return { x in
DispatchQueue.main.async {
f(x)
}
}
}