0

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.

zcoop98
  • 2,590
  • 1
  • 18
  • 31
Orkun
  • 6,998
  • 8
  • 56
  • 103

1 Answers1

1

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
});
tsegismont
  • 8,591
  • 1
  • 17
  • 27