这是一个例子:
return ApiClient.getPhotos()
.subscribeOn(Schedulers.io())
.map(new Func1<APIResponse<PhotosResponse>, List<Photo>>() {
@Override
public List<Photo> call(CruiselineAPIResponse<PhotosResponse> response) {
//convert the photo entities into Photo objects
List<ApiPhoto> photoEntities = response.getPhotos();
return Photo.getPhotosList(photoEntities);
}
})
.subscribeOn(Schedulers.computation())
Run Code Online (Sandbox Code Playgroud)
我是否需要两者.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)
Run Code Online (Sandbox Code Playgroud)
会印出类似的东西 ... RxCachedThreadScheduler-2
您可能需要observeOn(Schedulers.computation())将每个值(在本例中为List对象)的观察移动到另一个线程.
| 归档时间: |
|
| 查看次数: |
761 次 |
| 最近记录: |