-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Consume as flow #1343
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
Consume as flow #1343
Conversation
bc34a2e
to
f116346
Compare
kotlinx-coroutines-core/common/test/flow/channels/ChannelBuildersFlowTest.kt
Outdated
Show resolved
Hide resolved
f116346
to
bb4a835
Compare
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.
Otherwise looks good, please squash commits if you want, fix comments and I will merge it as soon as it's ready
* 1) Flow consumer is cancelled when the original channel is cancelled. | ||
* 2) Flow consumer completes normally when the original channel completes (~is closed) normally. | ||
* 3) If the flow consumer fails with an exception, channel is cancelled. | ||
* |
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.
extra indent
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.
Where?
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.
line 74
d5e12d2
to
e54272b
Compare
I've squashed and rearranged all the old commit into two logically grouped commits, fixing all the review issues:
I've added a 3rd (new) commit that makes |
* The corresponding ReceiveChannel methods are deprecated. * Introduced corresponding extensions with the same semantic and generic Any bound. * Introduce internal ReceiveChannel.[on]receiveOrClosed * Using internal inline class ValueOrClosed. * To be stabilized and made public in the future when inline classes ABI stabilizes. * It is related to #330 but does not resolve it yet. * Includes todos for future public ValueOrClose design. * Simplify AbstractChannel select implementations. * AbstractChannel implementation is optimized to avoid code duplication in suspension of different receive methods: receive, receiveOrNull, receiveOrClosed.
* This is a consuming conversion -- the resulting flow can be collected just once and the channel is closed after the first collect. * The implementation is made efficient via emitAll extension. * Experimental FlowCollector.emitAll extension is introduced. * It is based on the (internal) Channel.receiveOrClose and ensures that the reference to the last emitted value is not retained (does not leak). Fixes #1340 Fixes #1333
e54272b
to
d8a87f9
Compare
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.
LGTM
just once and the channel is closed after the first collect.
a new internal ReceiveChannel.consumeEachTo function which also ensure
that the reference to the last emitted value is not retained.
in different receive methods.