Tymmm1
12/13/2020, 9:25 PMcollect
just once from a StateFlow
or SharedFlow
? One can call cancel()
on the job of the coroutine that is collecting but that seems a bit cumbersome...Tijl
12/13/2020, 9:45 PMfirst()
Tymmm1
12/13/2020, 10:02 PMfirst()
unfortunately has different behavior from collect()
in that it throws an exception when the flow is empty.travis
12/13/2020, 10:02 PMfirstOrNull
Tymmm1
12/13/2020, 10:03 PMfirstOrNull
also has different behavior. It returns null if the flow is empty where collect
would just block and wait until there is something.Tijl
12/13/2020, 10:05 PMTymmm1
12/13/2020, 10:08 PMfirst()
when I was using it on a SharedFlow
(with no initial value).collect()
on a SharedFlow
no exception is thrown.Tijl
12/13/2020, 10:11 PMvalue
since reading that code it will be more clear it will not suspend ( first
behaves the same in this case but on other Flows like SharedFlow it can suspend)Tymmm1
12/13/2020, 10:19 PM