forBlockingFunc(queue:body:)

This function is a helper for calling blocking function from Task and properly suspend the Task while such call take place. The blocking function call happens in global dispatch queue and when it’s done calls continuation to resume suspended Task.

ForBlockingCall.swift:30
func forBlockingFunc<T>(queue: DispatchQueue = .global(), body: @escaping () -> T) async -> T

Parameters

queue

The queue where blocking call will be invoked

body

Function to be called in the queue

Returns

The function returns a value returned by body function

Usage example:

Task {
    let result = await forBlockingFunc {
        myBlockingFunction()
    }
    // end here only when myBlockingFunction() is done
}