suspend fun <T> AsyncResult<T>.await(): T
(source)
Awaits for completion of the AsyncResult 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 AsyncResult and immediately resumes with CancellationException.
Note, that AsyncResult does not support prompt removal of listeners, so on cancellation of this wait a few small objects will remain in the AsyncResult 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 AsyncResult never completes.