ubu
05/26/2018, 12:30 PMAsyncTransformer
class that looks like this:
class AsyncTransformer<T> : Transformer<T>() {
override fun apply(upstream: Observable<T>): ObservableSource<T> {
return upstream.subscribeOn(<http://Schedulers.io|Schedulers.io>()).observeOn(AndroidSchedulers.mainThread())
}
}
Then I have some chain of requests which looks like this:
masterRepository
.getMaster("uWynT16dspTQBTaiyKt5hgr3iBp1")
.flatMap { master -> Observable.fromIterable(master.orders)}
.flatMap { id -> orderRepository.getOrder(id) }
.flatMap { order -> customerRepository.getCustomer(order.customerId) }
Internally, in all these repositories I use Observable.create { ... }
to wrap async operations, calling onNext()
and, when there’s an error, onError()
. (I feel like there’s a problem here with this Observable.create {} flow; aren’t those observables cold, and if so, they should wait an observer? )
When this chain gets called (subscribed), AsyncTransformer
is applied. So I’d except everything above would run on IO thread
, but logging says it’s on the main thread
.
The only place where schedulers are applied, is in some controller which subscribes some view model which in its turn provides the data stream described above.
So why the main thread? And not the io
thread ’till we get the data we need in the controller.
Thanks.