yield
Yields the thread (or thread pool) of the current coroutine dispatcher to other coroutines on the same dispatcher to run if possible.
This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed when this suspending function is invoked or while this function is waiting for dispatch, it resumes with a CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.
Note: This function always checks for cancellation even when it does not suspend.
Implementation details
If the coroutine dispatcher is Unconfined, this functions suspends only when there are other unconfined coroutines working and forming an event-loop. For other dispatchers, this function calls CoroutineDispatcher.dispatch and always suspends to be resumed later regardless of the result of CoroutineDispatcher.isDispatchNeeded. If there is no CoroutineDispatcher in the context, it does not suspend.