这是一个例子:
return ApiClient.getPhotos() .subscribeOn(Schedulers.io()) .map(new Func1, List >() { @Override public List call(CruiselineAPIResponse response) { //convert the photo entities into Photo objects List photoEntities = response.getPhotos(); return Photo.getPhotosList(photoEntities); } }) .subscribeOn(Schedulers.computation())
我是否需要两者.subscribeOn(Schedulers.computation())
,.subscribeOn(Schedulers.computation())
因为它们适用于不同的Observable?
无需多次subscribeOn
通话; 在这种情况下,第二次调用在功能上是无操作,但在序列的持续时间内仍保留在某些资源上.例如:
Observable.just(1) .map(v -> Thread.currentThread()) .subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.computation()) .toBlocking() .subscribe(System.out::println)
会印出类似的东西 ... RxCachedThreadScheduler-2
您可能需要observeOn(Schedulers.computation())
将每个值(在本例中为List对象)的观察移动到另一个线程.