Javascript Like "Promise.all" on Java 8 (maybe with lambdas)

Alberto :

I would like to know if there is something similar to the "Promise.all" of JavaScript for Java 8 (currently on Android). I am trying to make when all the callbacks finish, then execute a second process.

Now the callbacks that I am using are lambdas expressions, but I'm open to suggestions to change the way to do the callbacks and the "big callback" that is executed when all callbacks finishes.

I made it with a counter of callbacks, that when that counter of callbacks is equal to the length of callbacks then call to the big callback. But I am sure that this solution is not the correct one.

Jeff Bowman supports Monica :

Java 8 offers this as CompletableFuture.allOf(CompletableFuture...), which mimics Promise.all; there is also CompletableFuture.anyOf(CompletableFuture...) to mimic Promise.race in Javascript.

If you use ListenableFuture instead, Guava does this as Futures.allAsList(...), with both varargs and iterable overloads.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=75949&siteId=1