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

zak.taccardi

03/27/2021, 6:48 PM
it still seems unclear whether to use
callbackFlow
vs
channelFlow
. It seems the latter respects operator fusion, but the prior does not?
d

Dominaezzz

03/27/2021, 7:08 PM
One of them will throw an exception if you don't call
awaitClose
.
Only use
callbackFlow
if you're dealing with callbacks. Use
channelFlow
otherwise.
z

zak.taccardi

03/27/2021, 7:09 PM
So they both respect operator fusion?
d

Dominaezzz

03/27/2021, 7:10 PM
The only difference between them is the exception throwing.
z

zak.taccardi

03/27/2021, 7:10 PM
I'm trying to think why I would ever want to use
channelFlow
because my only use case for it is to register/unregister callbacks
d

Dominaezzz

03/27/2021, 7:10 PM
Some people want to do concurrent
emit
.
👆🏼 1
👆 3
z

zak.taccardi

03/27/2021, 7:11 PM
Ah, interesting
u

ursus

03/28/2021, 2:12 PM
hmm why not just
flow { .. }
? i thought that builder was main selling point of flow
s

streetsofboston

03/28/2021, 3:39 PM
Because as soon as the provided lambda to the
flow
call ends/returns, the
Flow
that it returns ends/completes. The callback/channelFlow builders provide a suspending awaitClose method allowing this lambda to suspend indefinitely.
🙏 1
2 Views