为什么不推荐使用 Kotlin 通道上的流操作?

Why stream operations on Kotlin channels are deprecated?

如果您尝试对 Kotlin 中的通道使​​用任何流操作(mapfilter 等...),您将收到以下警告

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

我不确定我是否完全理解关于问题 #254 的讨论。为什么这些操作会过时?

如果我是对的就知道问题是,这些流操作 运行 不管是否有任何 subscriber (因为频道是热,我不确定为什么这是个问题...),方向是 优化它们 ,这样它们 运行 只有当有订户吗?

它们已被弃用,因为可以改用 Flow 运算符,并且他们不想重新定义通道的运算符。

编辑: 您可以通过 consumeAsFlow.

在频道上使用 Flow 流运算符