runSync(priority:_:)
Runs throwing async closure and waits for its result (incl. rethrowing exception) in non-async code.
func runSync<T>(priority: TaskPriority? = nil, _ operation: @escaping () async throws -> T) throws -> T where T : Sendable
Parameters
Returns
The value returned from the operation
.
Throws
The error thrown by the operation
.
Use with care as this blocks the current thread and violates “forward progress” Swift concurrency runtime contract.
See https://developer.apple.com/videos/play/wwdc2021/10254/?time=1582