I tried to implement `rx.Observable.switchMap` for...
# coroutines
h
I tried to implement
rx.Observable.switchMap
for Channels: https://gist.github.com/hannesstruss/927ec8120d7cb312d80685f230d50c6e It's kind of working ("just" deadlocking occasionally), but I found the way there to be very brittle, so much depends on using the right coroutine contexts in the right places. E.g. when not using
Unconfined
for
produce
in the
transform
function, the wrong channel will be selected in
whileSelect
and the outcome will be wrong. Any general hints on how to approach problems like that?
Updated to a less convoluted version that also gets rid of the channel race: https://gist.github.com/hannesstruss/927ec8120d7cb312d80685f230d50c6e This seems to work better now. Also getting rid of
TestCoroutineContext
helped to kill some deadlocks in the tests, sadly at a cost, since the `delay`s now actually take time. Feedback still welcome, I still don't really have an idea what I'm doing 🤔
v
Hi,
switchMap
is non-trivial one. You should also cancel
current
when receiving new event from
input
and propagate cancellation to downstream from
input
.
In general it looks good (though I haven’t tested it 🙂).
Unconfined
is recommended to use only for map/filter ops, not for coroutines: it’s very fragile “advanced” API