Best practice for blocking a thread on async work

Is there a best practice for calling async code and waiting for the result from a synchronous function? The talk called out semaphores as an incorrect solution. Do you recommend using a lock, a dispatch group, or something else?

(I suppose this is an anti-pattern in general but since it may rarely be useful, I'd like to know how best to do it.)

Thanks!

Here's an example of what I'd like to do:

func foo() -> Bool {
  var ok = false
  async {
    ok = await bar()
    // Signal completion
  }
  // Wait for completion
  return ok
}

Replies

Async/await is specifically built to not allow what you're describing here.

async {} returns a Task.Handle<> that allows cancellation or waiting on the result, but you have to wait on the Task with other async code. This is a strength, not a weakness, of async/await.