Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ChannelIterator.next non-suspending #1162

Closed
qwwdfsad opened this issue Apr 30, 2019 · 2 comments
Closed

Make ChannelIterator.next non-suspending #1162

qwwdfsad opened this issue Apr 30, 2019 · 2 comments

Comments

@qwwdfsad
Copy link
Collaborator

State machine allocation in ChannelIterator.next is, in fact, unnecessary as hasNext suspends and consumes an element from the channel anyway. Suspension in next was introduced to have shortcuts for operators like first that do not call hasNext at all.
The key point here is to make a binary compatible change

@fvasco
Copy link
Contributor

fvasco commented Apr 30, 2019

Hi @qwwdfsad,
maybe you have to update the documentation, also.
There is no mention to the hasNext method there, so the follow ugly example is licit :

fun main() = runBlocking {
    val channel = produce {
        repeat(3) {
            send(it)
            delay(10)
        }
    }
    val iterator = channel.iterator()
    repeat(3) {
        val i = iterator.next()
        println(i)
    }
}

@elizarov
Copy link
Contributor

@fvasco Good catch. Docs will have to be updated, too.

qwwdfsad added a commit that referenced this issue May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants