Hey everyone, when I'm converting a callback based...
# coroutines
j
Hey everyone, when I'm converting a callback based API to a
Flow
using
callbackFlow
, do I have to call
close()
after
trySend(...)
when the call back only emits once?
g
Depends on your use case
If you call close(), flow will cancrl
It's not necessary what you want, because it means it doesn't support multiple emissions
And if it's the case, maybe you don't need flow at all and suspend function is enough
j
The callback will only every emit once.
g
In this case you need suspens function
j
The context needs a
Flow
sadly
g
You can convert suspend function to flow, there is an extension for this
j
Oh nice!
I'll check it out
Do you have the name of the function on top of your head by any chance?
Thanks for you help!
l
You can also just do
flow { emit(someSuspendFunction()) }
👍 1
g
yep, also an option of course. Just like explicitness of converter
👍 1