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

diesieben07

11/16/2020, 10:58 AM
How do I properly clean up resources when using
flow
? For example if I open an IO Stream in the
flow {}
builder, how do I clean it up? I can't use
onCompletion
, because I don't have the stream available there obviously. If I understand the docs correctly I am not supposed to use
try-finally
in the
flow {}
builder, correct?
1
f

flosch

11/16/2020, 11:05 AM
You could use
callbackFlow
which has an
awaitClose
in its lambda scope
👍 3
d

diesieben07

11/16/2020, 11:09 AM
Ah of course. I completely forgot about that one 🤦 thank you
6 Views