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.
func forBlockingFunc<T>(queue: DispatchQueue = .global(), body: @escaping () -> T) async -> T
Parameters
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
}