I have three methods which return future, how do I properly chain them so that output from first one is passed to the second and second's return to third and finally send them all of the above data to final future. I am not sure this is the correct way to approach this problem.
Source
.fromFuture(someFuture)
.mapAsync(1)(modelData => queryModelData(modelQuery))
.mapAsync(1)(modelId => findModelId(modelData))
.mapAsync(1)(jobData => queryJobData(jobQuery))
.mapAsync(1)(status => setModelStatus(modelData,modelId,jobData))
You can chain multiple Futures sequentially using .flatMap
(or a for-comprehension which is syntactic sugar for the same).
e.g.
Source
.fromFuture(someFuture)
.mapAsync(1){ data =>
for {
modelData <- queryModelData(data)
modelId <- findModelId(modelData)
jobData <- queryJobData(modelId)
status <- setModelStatus(modelData, modelId, jobData)
} yield status
}