https://kotlinlang.org logo
#coroutines
Title
# coroutines
k

kevin.cianfarini

02/10/2020, 3:53 PM
Is there any reason that
channelFlow
doesn't expose something like
fun channelFlow(buffer: Int = ...)
And instead we have to call
.buffer
downstream?
👀 1
z

Zach Klippenstein (he/him) [MOD]

02/10/2020, 4:02 PM
It would be confusing to have code that looks like:
Copy code
channelFlow(buffer = UNLIMITED) {
  …
}.conflate()
Because the two buffer specifications would compete (since the operators are fused under the hood and use a single channel), and only one of the specifications would actually be used.
k

kevin.cianfarini

02/10/2020, 4:03 PM
The missing piece I had was that operators are fused.
knowing that solves this question
here's the bit in question
Copy code
return if (this is ChannelFlow)
        update(capacity = capacity)
    else
        ChannelFlowOperatorImpl(this, capacity = capacity)
👍 1
and from the docs for anyone who reads this later
Adjacent applications of channelFlow, flowOn, buffer, produceIn, and broadcastIn are always fused so that only one properly configured channel is used for execution.
👍 2