Skip to content

use-like extensions on ReceiveChannel and SendChannel #429

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

Closed
elizarov opened this issue Jul 8, 2018 · 3 comments
Closed

use-like extensions on ReceiveChannel and SendChannel #429

elizarov opened this issue Jul 8, 2018 · 3 comments

Comments

@elizarov
Copy link
Contributor

elizarov commented Jul 8, 2018

So, we have ReceiveChannel and SendChannel

  • If you've done working with SendChannel you should close it (send termination message)
  • If you've done working with ReceiveChannel you should cancel it (indicate that you no longer planning to receive anything and sending coroutine should be cancelled).

Currently we have ReceiveChannel.consume extension. The design goal behind it was that it shall "consume" channel by making sure it is always closed at the end. However, it is inconvenient in two aspects:

  • Unlike Closeable.use it provides the channel as this. This seems to be a bad design decision in retrospect.
  • If consuming coroutine crashes with exception, then it cancels producer with the same exception. It is not clear if that is good or bad idea at the moment.

We don't anything similar for SendChannel channel.

It looks like we should define some additional use-like extensions and ReceiveChannel and SendChannel that cancel and close then correspondingly and provide the corresponding channel in the use-style, so that you can chain channel-producing operators like this:

doSomethingThatProduceChannel(...).use { chan -> ... }

But we cannot name both ReceiveChannel and SendChannel extension as use and they would conflict on Channel interface. It would be great is ReceiveChannel extension was actually named consume but we cannot easily retrofit existing consume so that it provide channel as a parameter instead of this in a backwards-compatible way.

This is an open question on what to do.

@elizarov elizarov changed the title "use"-link extensions on ReceiveChannel and SendChannel use-like extensions on ReceiveChannel and SendChannel Jul 8, 2018
@elizarov elizarov changed the title use-like extensions on ReceiveChannel and SendChannel use-like extensions on ReceiveChannel and SendChannel Jul 8, 2018
@kevinherron
Copy link

kevinherron commented Jul 12, 2018

Deprecate consume, introduce drain with channel as parameter?

@elizarov
Copy link
Contributor Author

@kevinherron drain is nice name. Thanks for the idea.

@qwwdfsad
Copy link
Member

qwwdfsad commented Sep 7, 2021

Since 2018 we have introduced a lot of primitives that replace the SendChannel for most of the use-cases: produce, callbackFlow, StateFlow and SharedFlow.

Closing as no longer relevant

@qwwdfsad qwwdfsad closed this as completed Sep 7, 2021
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