[英]How to process each iteration of list of items in rxjava with retrofit in Android
我是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());
请帮助并提前感谢您...
首先在observeOn(AndroidSchedulers.mainThread())
调用会强制所有后续运算符在主线程上运行,然后抛出NetworkOnMainThreadException
。
尝试将此呼叫移至subscribe
之前的最后一点:
// ...
.observeOn(AndroidSchedulers.mainThread())
.subscribe(res -> doStuff(),
throwable -> showThrowable());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.