-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Implement receiveOrClosed for channels and select clause #330
Comments
I agree with you, but in my experience the |
Let me clarify that the considerable fraction of value is going to come from support for Note, that when we have
will not work as expected. We shall make sure it fails fast in this case with a clear error message. Another note, is that we should not actually expose |
You are right @elizarov select {
channel.onClose { ... } // onClose first
channel.onReceive { ... }
}
|
Typical behavior of `Channel` is to throw a `ClosedReceiveChannelException` on invocation of `close` if a `receive` is suspended. This is unfortunately a bit counter intuitive and can produce misleading stacktraces. In order to be more explicit with our exception stacktraces related to `Channel` cancelation, using `receiveOrNull` and explicitly throwing `GattClosed` exception when receiving `null`. May need to revisit this behavior in the future after `receiveOrClosed` is implemented per Kotlin/kotlinx.coroutines#330. Also noteworthy is that `receiveOrNull` was undeprecated via Kotlin/kotlinx.coroutines#739.
Typical behavior of `Channel` is to throw a `ClosedReceiveChannelException` on invocation of `close` if a `receive` is suspended. This is unfortunately a bit counter intuitive and can produce misleading stacktraces (i.e. stacktrace will include `close` invocation but not `receive`). In order to be more explicit with our exception stacktraces related to `Channel` cancelation: catching `ClosedReceiveChannelException` and explicitly throwing `GattClosed` exception (that carries original `ClosedReceiveChannelException` as it's cause). May need to revisit this behavior in the future after `receiveOrClosed` is implemented per Kotlin/kotlinx.coroutines#330.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* Introduce three-state ChannelResult, a domain-specific Result class counterpart * Introduce receiveCatching/onReceiveCatching, make it public * Get rid of receiveOrClosed/onReceiveOrClosed without migrations, it was @InternalCoroutinesApi anyway Fixes #330
* Introduce three-state ChannelResult, a domain-specific Result class counterpart * Introduce receiveCatching/onReceiveCatching, make it public * Get rid of receiveOrClosed/onReceiveOrClosed without migrations, it was @InternalCoroutinesApi anyway Fixes #330
* Introduce three-state ChannelResult, a domain-specific Result class counterpart * Introduce receiveCatching/onReceiveCatching, make it public * Get rid of receiveOrClosed/onReceiveOrClosed without migrations, it was @InternalCoroutinesApi anyway Fixes #330
* Introduce three-state ChannelResult, a domain-specific Result class counterpart * Introduce receiveCatching/onReceiveCatching, make it public * Get rid of receiveOrClosed/onReceiveOrClosed without migrations, it was @InternalCoroutinesApi anyway Fixes #330
* Introduce three-state ChannelResult, a domain-specific Result class counterpart * Introduce receiveCatching/onReceiveCatching, make it public * Get rid of receiveOrClosed/onReceiveOrClosed without migrations, it was @InternalCoroutinesApi anyway Fixes #330
Will be named |
That bug has been fixed. What is the status for this? |
It will be added to coroutines 1.5.0 under It's already implemented and merged, the rationale of naming is explained in this comment |
* Introduce three-state ChannelResult, a domain-specific Result class counterpart * Introduce receiveCatching/onReceiveCatching, make it public * Get rid of receiveOrClosed/onReceiveOrClosed without migrations, it was @InternalCoroutinesApi anyway Fixes Kotlin#330
We need
receiveOrClosed
method on top of channels andonReceiveOrClosed
forselect
which will have return typeEither<E, CloseToken>
.Currently, pattern to work with channels always has the following form which is clumsy and obfuscates code:
The better alternative may be
For implementation to be efficient we need inline classes (Kotlin/KEEP#104)
The text was updated successfully, but these errors were encountered: