runSync(priority:_:)

Runs async closure and waits for its result in non-async code.

RunSync.swift:18
func runSync<T>(priority: TaskPriority? = nil, _ operation: () async -> T) -> T

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.

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