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

Zach Klippenstein (he/him) [MOD]

09/06/2019, 6:26 PM
I feel like there have been a lot of questions recently about the difference between
callbackFlow
and
channelFlow
(e.g. https://github.com/Kotlin/kotlinx.coroutines/issues/1500). The rationale for having two separate aliases for the same function is that “have different names to tailor their docs the the speicific use-case and to enable the code using them to convey your intention.” Is the distinction between them really providing enough value to justify all the confusion they seem to be creating? It seems like the documentation could be merged, and I don’t fully understand how much value is really added by making “intent” clearer – in what case would choosing one over the other actually make code significantly clearer? If callbacks are being used, it will be apparent in the code because there’ll be lambdas and
addListener
calls everywhere. Additionally, RxJava users have gotten used to using
Observable.create { }
for integrating with callback-based APIs even though it doesn’t have “callback” in the name anywhere.
p

Pablichjenkov

09/07/2019, 1:23 AM
If I have to pick one name I would pick "channelFlow".
👍 1
z

Zach Klippenstein (he/him) [MOD]

09/07/2019, 2:03 AM
Me too –
callbackFlow
seems too focused on a particular use case
👍 1
p

Pablichjenkov

09/07/2019, 9:36 PM
Agree
6 Views