in kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt [1626:1650]
override suspend fun hasNext(): Boolean {
return if (this.receiveResult !== NO_RECEIVE_RESULT && this.receiveResult !== CHANNEL_CLOSED) {
true
} else receiveImpl( // <-- this is an inline function
// Do not create a continuation until it is required;
// it is created later via [onNoWaiterSuspend], if needed.
waiter = null,
// Store the received element in `receiveResult` on successful
// retrieval from the buffer or rendezvous with a suspended sender.
// Also, inform the `BufferedChannel` extensions that
// the synchronization of this receive operation is completed.
onElementRetrieved = { element ->
this.receiveResult = element
true
},
// As no waiter is provided, suspension is impossible.
onSuspend = { _, _, _ -> error("unreachable") },
// Return `false` or throw an exception if the channel is already closed.
onClosed = { onClosedHasNext() },
// If `hasNext()` decides to suspend, the corresponding
// `suspend` function that creates a continuation is called.
// The tail-call optimization is applied here.
onNoWaiterSuspend = { segm, i, r -> return hasNextOnNoWaiterSuspend(segm, i, r) }
)
}