-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ChannelIterator: add an example #4539
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
base: master
Are you sure you want to change the base?
Conversation
…he channel, with their own iterator instance
| * Iterator for a [ReceiveChannel]. | ||
| * Instances of this interface are *not thread-safe* and shall not be used from concurrent coroutines. | ||
| * Instances of this interface are *not thread-safe*. | ||
| * Each iterator instance should be used by a single coroutine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not true, it can be passed around different coroutines as long as this doesn't result in multithreaded access.
| * Instances of this interface are *not thread-safe*. | ||
| * Each iterator instance should be created and used by a single coroutine. | ||
| * | ||
| * An example usage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe the sequence of events where this sample would answer a question a user may realistically have? It neither explains the next()/hasNext() interplay useful in deeply technical cases where you'd manipulate ChannelIterator manually, nor does it spell out "hey, this is not the class that you need to use manually, just write for (... in ...) instead" if that was the intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm addressing my own confusion with the original wording - it primed me to think that only one coroutine is allowed to create instances of the iterator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added wording on "don't use directly" and "next/hasNext"
Add an example, stress that different coroutines can iterate over the channel, with their own iterator instance