https://kotlinlang.org logo
Title
w

withoutclass

01/30/2018, 4:16 PM
Is this pyramid of death style of receiving from channels pretty common or am I doing something silly?
launch {
        whileSelect {
            channel.onReceive {
                when (it) {
// do stuff
                 }
             }
        }
}
e

elizarov

01/30/2018, 8:59 PM
You don’t need
whileSelect
here. Use
for (msg in channel)
w

withoutclass

01/30/2018, 9:02 PM
the
for (msg in channel)
will stop looping once there are no events though, correct? I want to continue listening on the channel even if there are 0 events.
e

elizarov

01/30/2018, 9:46 PM
Listening for what?
w

withoutclass

01/30/2018, 9:49 PM
More events. I’m using the channel like an Rx.Observable in that I expect to receive events as actions happen on the UI of an application, such as
onClick { channel.send(event) }
. It works very well, though maybe I’m doing it incorrectly.
e

elizarov

01/30/2018, 9:50 PM
That is what
for
loop does.
w

withoutclass

01/30/2018, 9:53 PM
Ok thank you for the help 🙂