abstract suspend operator fun hasNext(): Boolean(source)

Returns true if the channel has more elements, suspending the caller while this channel is empty, or returns false if the channel is closed for receive without a cause. It throws the original close cause exception if the channel has failed.

This function retrieves and removes an element from this channel for the subsequent invocation of next.

This suspending function is cancellable: if the Job of the current coroutine is cancelled while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee: even if hasNext retrieves the element from the channel during its operation, but was cancelled while suspended, CancellationException will be thrown. See suspendCancellableCoroutine for low-level details.

Because of the prompt cancellation guarantee, some values retrieved from the channel can become lost. See "Undelivered elements" section in Channel documentation for details on handling undelivered elements.

Note that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.