Hey, this may be a bias channel to ask this but do...
# reaktive
m
Hey, this may be a bias channel to ask this but do you have an opinion for usecases of reaktive vs normal coroutine flows? Thanks!
a
Good question! There are a couple of main points to consider. 1. From my point of view it is mostly just a matter of preference. E.g. I don't like the imperative style of coroutines. 2. Coroutines have been more difficult to debug so far, e.g. there are issues with breakpoints. 3. Testing of coroutines-based code is also not that easy. One of the examples - https://twitter.com/arkann1985/status/1573803236271726593
d
RX is general approach, you can find implementation for other platforms Coroutines is a new bicycle ­čśâ
m
but flows do have all transforms and stuff, so it is reactive, no?
a
Also there is a feature of coroutines - "execution context never leaks downstream". But personally I find this feature more like a limitation. This is often annoying with MVI-like approaches.
but flows do have all transforms and stuff, so it is reactive, no?
Flow does, but a direct equivalent for Single would be
typealias Single<T> = suspend () -> T
. Completable would be
typealias Completable = suspend () -> Unit
Obviously nobody would use coroutines this way :-)
Exactly because of "execution context never leaks downstream" you have to specify a context when collecting a Flow (executing a suspend function). This may lead to bugs like in this article, when you use a redispatching dispatcher by mistake (or because it's used by default). With Rx this would happen only if you explicitly use
observeOn
or
subscribeOn
.
But in general this is just a matter of preference.
m
sounds good thanks for the context!