next
Retrieves the element removed from the channel by the preceding call to hasNext, or throws an IllegalStateException if hasNext was not invoked.
This method can only be used together with hasNext:
while (iterator.hasNext()) {
val element = iterator.next()
// ... handle the element ...
}
Content copied to clipboard
A more idiomatic way to iterate over a channel is to use a for
loop:
for (element in channel) {
// ... handle the element ...
}
Content copied to clipboard
This method never throws if hasNext returned true
. If hasNext threw the cause with which the channel was closed, this method will rethrow the same exception. If hasNext returned false
because the channel was closed without a cause, this method throws a ClosedReceiveChannelException.