runSync(priority:_:)

Runs throwing async closure and waits for its result (incl. rethrowing exception) in non-async code.

RunSync.swift:51
func runSync<T>(priority: TaskPriority? = nil, _ operation: @escaping () async throws -> T) throws -> T where T : Sendable

Parameters

priority

The priority of the task that will run the operation. Pass nil to use the priority from Task.currentPriority.

operation

The operation to perform.

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