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

jw

02/22/2018, 4:33 AM
i'm using a ConflatedChannel for a view model so that it can be updated while there's no view to consume but when the view comes back it gets the latest. This works great, except it appears that the incoming view always has to suspend to get that buffered instance. This means that the view state gets restored before the data (which then effectively drops the state). Is there a way to have a consumer of a conflated channel receive the last known value (if any) synchronously inside an unconfined coroutine? Or is there something else built-in that I can use for this?
👍 1
d

dave08

02/22/2018, 8:35 AM
runBlocking(UI)
... I think this is maybe a valid reason to use it and not fail-fast like the proposed issue in Github (since you're sure you're not doing anything that'll block for too long)... I had suggested that one should be able to opt-out from fail-fast... but I think you could always use
poll
on the channel to not suspend instead of
receive
and just loop until you get a value from it, that could be made into an extension function ...
☝️ 1
j

jw

02/23/2018, 4:26 AM
Hmm
poll()
doesn't seem to work. I always get null.
Nevermind I'm an idiot. The event was already consumed by the old receiver.
d

dave08

02/23/2018, 6:05 AM
Glad you solved your problem 😃