Reputation: 7228
I am chaining some calls and I need to use the outcome of 1 future in a following call.
In the example below, what would be the most elegant way to be able to use res1
?
call1()
.compose(res1 -> call2(res1))
.compose(res2 -> call3(res2, res1)) // cannot user res1 here!!
.setHandler(res -> {
/// omitted for brevity
});
I can make call2
return a map containing res1
and res2
but I wonder if there is another way.
Upvotes: 0
Views: 805
Reputation: 9128
In this case you should compose
the result of call2
inside the lambda where res1
is accessible:
call1().compose(res1 -> {
return call2(res1).compose(res2 -> call3(res2, res1));
}).setHandler(res -> {
// omitted for brevity
});
Upvotes: 1