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

elizarov

12/13/2017, 8:41 AM
@louiscad I'd define
val connectionStatus = ConflatedBroadcastChannel<Boolean>(false)
to keep connected/disconnected status and then whenever I need to wait for it being connected I'd do
connectionStatus.consume { while (!receive()) { /* do nothing */ } }
l

louiscad

12/13/2017, 9:07 AM
@elizarov Seems neat! The
receive()
docs say calling it "removes from the channel", but this statement is false for `BroadcastChannel`s, right? Also, what does
Conflated
means exactly?
Here's what I could implement with your suggestion: https://gist.github.com/LouisCAD/0d57c65bc9dd2e45135942e8ffb365bf Is this right? EDIT: Just edited the gist to add an
isLocked
property.
e

elizarov

12/13/2017, 10:17 AM
receive()
removes from the channel, but here we are working with
BroadcastChannel
, so each consumer opens its own channel that receives its own copy of the value that was sent.
👍🏽 1
Conflated
means that it stores the most recently sent value, so if you start consuming, then the first thing that is receive it the last state that was sent.
👍🏽 1