We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents cfa07b6 + 3aa4fbe commit bdc048eCopy full SHA for bdc048e
stdlib/public/Concurrency/Actor.swift
@@ -43,3 +43,17 @@ fileprivate func _registerMainActor(actor: AnyObject)
43
_registerMainActor(actor: self)
44
}
45
46
+
47
+extension MainActor {
48
+ /// Execute the given body closure on the main actor.
49
+ public static func run<T>(
50
+ resultType: T.Type = T.self,
51
+ body: @MainActor @Sendable () throws -> T
52
+ ) async rethrows -> T {
53
+ @MainActor func runOnMain(body: @MainActor @Sendable () throws -> T) async rethrows -> T {
54
+ return try body()
55
+ }
56
57
+ return try await runOnMain(body: body)
58
59
+}
0 commit comments