Why stream operations on Kotlin channels are deprecated?

Viewed 2019

If you try to use any of the stream operations for channels in Kotlin (map, filter, etc...) you'll get the following warning

Note: This API will become obsolete in future updates with introduction of lazy asynchronous streams. See issue #254.

I'm not sure I totally understand the discussion about issue #254. Why will these operations become obsolete?

If I'm correct right know the problem is, that these stream operations run regardless if there is any subscriber (since channels are hot, I'm not sure why that's a problem...), and the direction would be to optimise them, so that they run only when there is a subscriber?

1 Answers

They are deprecated because the Flow operators can be used instead and they don't want to redefine the operators for channels.

Edit: You can use the Flow stream operators on a Channel via consumeAsFlow.

Related