i'm using a ConflatedChannel for a view model so t...
# coroutines
j
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
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
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
Glad you solved your problem 😃