tuweni / org.apache.tuweni.concurrent.coroutines / org.apache.tuweni.concurrent.AsyncCompletion / await

await

suspend fun AsyncCompletion.await(): Unit (source)

Awaits for completion of the AsyncCompletion without blocking a thread.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function stops waiting for the AsyncCompletion and immediately resumes with CancellationException.

Note, that AsyncCompletion does not support prompt removal of listeners, so on cancellation of this wait a few small objects will remain in the AsyncCompletion stack of completion actions until it completes itself. However, care is taken to clear the reference to the waiting coroutine itself, so that its memory can be released even if the AsyncCompletion never completes.