Vavr: Get results of a execution of futures in a list

Created on 30 Apr 2018  路  2Comments  路  Source: vavr-io/vavr

Hi,

I'm getting the handle with Vavr and I'm finding it very usefull (and cool) but since unfortunately the version is still under 1.0.0 there's no wide documentation above but following some GitHub issues and Vavr JavaDoc I figured something like this for a multiple execution of futures:

Future.sequence( List.of( Future.of(() -> doSth()), Future.of(() -> doSthElse()), Future.of(() -> doSthElseMore()) ) ).onComplete(result -> { //... });

From debug, I can get that the head object contains the doSth() result and the remaining pair of results in the queue object.

What's the best practice to get the do*() results in the onComplete?

question 芦vavr-concurrent禄

All 2 comments

Hi @grimimirg, thank you for using Vavr!
Yes, that is exactly the way how to get multiple adync results in sync!
Another possibility would be a flatMap*-map cascade but it is only useful if you don鈥榯 want to operate on sequences:

future1.flatMap(v1 ->
    future2.flatMap(v2 ->
        future3.map(v3 -> buildYourResult(v1, v2, v3))
    )
);

or if you prefer to create side-effects use onComplete...

I hope that helps. We will improve our documentation with Vavr 1.0.

Hi @danieldietrich thank you for your answer! I'll proceed like that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maystrovyy picture maystrovyy  路  3Comments

roookeee picture roookeee  路  5Comments

nfekete picture nfekete  路  5Comments

civitz picture civitz  路  6Comments

bhchandra picture bhchandra  路  3Comments