【发布时间】:2019-03-14 19:53:44
【问题描述】:
我正在使用RxJava,我知道concat,我想它确实适合我,因为我想先完成所有第一次通话,然后再进行第二次通话,但我不知道如何实施它。
从现在开始我有这个:
private fun assignAllAnswersToQuestion(questionId: Long) {
answerListCreated.forEach { assignAnswerToQuestion(questionId, it.id) }
}
private fun assignAnswerToQuestion(questionId: Long, answerId: Long) {
disposable = questionService.addAnswerToQuestion(questionId,answerId,MyUtils.getAccessTokenFromLocalStorage(context = this))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
result -> //Do nothing it should call the next one
},
{ error -> toast(error.message.toString())}
)
}
但是,一旦这一切都完成了forEach,我想做这样的事情:
private fun assignAllAnswersToQuestion(questionId: Long) {
answerListCreated.forEach { assignAnswerToQuestion(questionId, it.id)
anotherCallHere(questionId) //Do it when the first forEach is finished!!
}
有什么想法吗?
另外,这是一种使用协程的方法吗?
【问题讨论】: