最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Jan 29, 2019 at 16:33 AlbertoAlberto 1,48919 silver badges32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 21

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.

发布评论

评论列表(0)

  1. 暂无评论