K Merle
05/15/2022, 8:51 AMcallbackFlow
but I do not need awaitClose()
callback. What would be a good candidate for it in flow?Chrimaeon
05/15/2022, 9:11 AMawaitClose()
block empty?K Merle
05/15/2022, 11:53 AMChrimaeon
05/15/2022, 11:58 AMfun foo() = flow {
emit(true)
}
this is a valid “flow”Chrimaeon
05/15/2022, 12:00 PMawaitClose()
that callbackFlow
provides you can use the basic flow builder.Oleg Yukhnevich
05/15/2022, 1:19 PMK Merle
05/15/2022, 1:23 PMemit
inside of the lambda gives me compile warning in a sense "emit can only be called within suspend function".K Merle
05/15/2022, 1:35 PMchannelFlow
body, like no one is consuming it. I'll look into it. For now best option seems to just leave awaitClose()
empty as @Chrimaeon suggested.Nick Allen
05/15/2022, 7:46 PMchannelFlow
and callbackFlow
are the same except callbackFlow
now throws if you don’t call awaitClose
(it didn't in the past). The channel is closed when the generator lambda completes. That’s why you need awaitClose
there even if there's nothing to clean up.
Btw, if you can change code such that there is a way to clean up in awaitClose
, I’d go ahead and do I it. Without that you are likely leaking something beyond your coroutine and that can cause subtle bugs ( like a resource used by a leaked listener after it's been closed).louiscad
05/15/2022, 8:44 PMMichal Klimczak
06/12/2022, 10:52 AM