Matej Drobnič
08/27/2019, 9:49 AMlaunch {
val channelA = openChannelA()
val channelB = openChannelB()
val channelC = openChannelC()
while (isActive) {
select {
channelA.onReceive {
...
}
channelB.onReceive {
...
}
channelC.onReceive {
...
}
}
}
}
However, I also want all of those channels closed if the actor is terminated for any reasonconsume
does that, but it is very ugly:
launch {
val channelA = openChannelA()
val channelB = openChannelB()
val channelC = openChannelC()
channelA.consume {
channelB.consume {
channelC.consume {
while (isActive) {
select {
channelA.onReceive {
...
}
channelB.onReceive {
...
}
channelC.onReceive {
...
}
}
}
}
}
}
}
gildor
08/27/2019, 10:18 AMMatej Drobnič
08/27/2019, 10:56 AMMarko Mitic
08/27/2019, 11:29 AMopenChannelA/B/C()
launches a coroutine in same scope as actor, all those will be canceled with the actor and your channels will be garbage collected eventuallygildor
08/27/2019, 11:32 AMlaunch
scope as Marko suggestingMatej Drobnič
08/27/2019, 11:37 AMopenChannelA()
do not perform any launchersFlowable.openSubscription()
from rx integration is not scope-awareMarko Mitic
08/27/2019, 11:55 AMgildor
08/27/2019, 1:22 PMfor exampleDo not use it, instead use Flowable.asFlow, that it will be perfectly lifecycle-safe and scope-aware Channel is actually bad wrapper for Flowablefrom rx integration is not scope-awareFlowable.openSubscription()
Matej Drobnič
08/27/2019, 1:26 PMgildor
08/27/2019, 1:30 PMMatej Drobnič
08/27/2019, 1:31 PMgildor
08/27/2019, 1:33 PMflattenMerge()
operatorMatej Drobnič
08/27/2019, 1:48 PMgildor
08/28/2019, 12:33 AMMatej Drobnič
08/28/2019, 5:37 AMgildor
08/28/2019, 5:44 AM