I need to create dependent API calls where the second one needs a value returned by the first one. First thing that comes to mind is using flatMap
ApiManager.shared
.createReport(report: report)
.flatMap { (report) -> Observable<Report> in
return ApiManager.shared.createReportStep(reportID: report.ID)
}
createReport
returns Observable<Report>
where after successfull call returns updated Report
model(with ID), after that I need to call API to create report step, where report.ID
is needed.
Everything looks and works fine with that code, but the problem comes when I need to do something after each of these steps(createReport
and createReportStep
). I placed code in onNext
block, but it is called only once, after both of the steps are completed.
Is there a way to receive onNext signal after both steps? I could use something like this:
ApiManager.shared
.createReport(report: report)
.concat(ApiManager.shared.createReportStep(reportID: report.ID))
Which would emmit two signals like I want, but then again where do I get updated report.ID
from to pass to createReportStep
?