@@ -295,25 +295,34 @@ public interface ChannelIterator<out E> {
295
295
*/
296
296
public suspend operator fun hasNext (): Boolean
297
297
298
+ @Deprecated(message = " Since 1.3.0, binary compatibility with versions <= 1.2.x" , level = DeprecationLevel .HIDDEN )
299
+ @Suppress(" INAPPLICABLE_JVM_NAME" )
300
+ @JvmName(" next" )
301
+ public suspend fun next0 (): E {
302
+ /*
303
+ * Before 1.3.0 the "next()" could have been used without invoking "hasNext" first and there were code samples
304
+ * demonstrating this behavior, so we preserve this logic for full binary backwards compatibility with previously
305
+ * compiled code.
306
+ */
307
+ if (! hasNext()) throw ClosedReceiveChannelException (DEFAULT_CLOSE_MESSAGE )
308
+ return next()
309
+ }
310
+
298
311
/* *
299
- * Retrieves and removes the element from this channel suspending the caller while this channel
300
- * is empty or throws [ClosedReceiveChannelException] if the channel
301
- * [isClosedForReceive][ReceiveChannel.isClosedForReceive] without cause.
302
- * It throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
303
- *
304
- * This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this
305
- * function is suspended, this function immediately resumes with [CancellationException].
306
- *
307
- * *Cancellation of suspended receive is atomic* -- when this function
308
- * throws [CancellationException] it means that the element was not retrieved from this channel.
309
- * As a side-effect of atomic cancellation, a thread-bound coroutine (to some UI thread, for example) may
310
- * continue to execute even after it was cancelled from the same thread in the case when this receive operation
311
- * was already resumed and the continuation was posted for execution to the thread's queue.
312
+ * Retrieves the element from the current iterator previously removed from the channel by preceding call to [hasNext] or
313
+ * throws [IllegalStateException] if [hasNext] was not invoked.
314
+ * [next] should only be used in pair with [hasNext]:
315
+ * ```
316
+ * while (iterator.hasNext()) {
317
+ * val element = iterator.next()
318
+ * // ... handle element ...
319
+ * }
320
+ * ```
312
321
*
313
- * Note that this function does not check for cancellation when it is not suspended .
314
- * Use [yield] or [CoroutineScope.isActive] to periodically check for cancellation in tight loops if needed .
322
+ * This method throws [ClosedReceiveChannelException] if the channel [isClosedForReceive][ReceiveChannel.isClosedForReceive] without cause .
323
+ * It throws the original [close][SendChannel.close] cause exception if the channel has _failed_ .
315
324
*/
316
- public suspend operator fun next (): E
325
+ public operator fun next (): E
317
326
}
318
327
319
328
/* *
0 commit comments