我是RxJava编程的新手,我想询问如何处理我从改装调用中获得的每个列表迭代。基本上我想做的是:
到目前为止,这是我的代码
Observable<List<Appointment>> callAppointments = appointmentServiceRx.getService().getConfirmedAppointments(user_id);
callAppointments.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMapIterable(apps -> apps)
.concatMap(app -> getPatientById(app)
.doOnNext(this::addPatientNames)
.map(patient -> app)
).concatMap(app -> getSubserviceById(app)
.doOnNext(this::addSubserviceNames)
.map(subservice -> app)
).toList()
.subscribe(res -> doStuff(),
throwable -> showThrowable());
请提前帮助并表示感谢...
答案 0 :(得分:0)
开头的observeOn(AndroidSchedulers.mainThread())
调用强制所有后续运算符在主线程上运行,然后抛出NetworkOnMainThreadException
。
尝试将此调用移至subscribe
:
// ...
.observeOn(AndroidSchedulers.mainThread())
.subscribe(res -> doStuff(),
throwable -> showThrowable());