{"action":"opened","issue":{"url":"https://api.github.com/repos/javaslang/javaslang/issues/1093","repository_url":"https://api.github.com/repos/javaslang/javaslang","labels_url":"https://api.github.com/repos/javaslang/javaslang/issues/1093/labels{/name}","comments_url":"https://api.github.com/repos/javaslang/javaslang/issues/1093/comments","events_url":"https://api.github.com/repos/javaslang/javaslang/issues/1093/events","html_url":"https://github.com/javaslang/javaslang/issues/1093","id":132386400,"number":1093,"title":"Future.parallel()","user":{"login":"ruslansennov","id":1582377,"avatar_url":"https://avatars.githubusercontent.com/u/1582377?v=3","gravatar_id":"","url":"https://api.github.com/users/ruslansennov","html_url":"https://github.com/ruslansennov","followers_url":"https://api.github.com/users/ruslansennov/followers","following_url":"https://api.github.com/users/ruslansennov/following{/other_user}","gists_url":"https://api.github.com/users/ruslansennov/gists{/gist_id}","starred_url":"https://api.github.com/users/ruslansennov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruslansennov/subscriptions","organizations_url":"https://api.github.com/users/ruslansennov/orgs","repos_url":"https://api.github.com/users/ruslansennov/repos","events_url":"https://api.github.com/users/ruslansennov/events{/privacy}","received_events_url":"https://api.github.com/users/ruslansennov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-09T10:43:24Z","updated_at":"2016-02-09T10:43:24Z","closed_at":null,"body":"Toward #186 we can create this static factory\r\n```java\r\nstatic <T> Future<Seq<T>> parallel(Iterable<? extends Future<? extends T>> futures) {\r\n    Objects.requireNonNull(futures, \"futures is null\");\r\n    return new FutureSet<>(DEFAULT_EXECUTOR_SERVICE, futures).result();\r\n}\r\n```\r\nwith implemented in <code>FutureModule</code>\r\n```java\r\nclass FutureSet<T> {\r\n\r\n    private Set<Future<? extends T>> uncompleted;\r\n    private Seq<T> seq = Stream.empty();\r\n    private final Promise<Seq<T>> result;\r\n    private final Object lock = new Object();\r\n\r\n    FutureSet(ExecutorService executorService, Iterable<? extends Future<? extends T>> futures) {\r\n        uncompleted = HashSet.ofAll(futures);\r\n        result = Promise.make(executorService);\r\n        futures.forEach(f -> f.onSuccess(t -> {\r\n            synchronized (lock) {\r\n                uncompleted = uncompleted.remove(f);\r\n                seq = seq.append(t);\r\n                if (uncompleted.isEmpty()) {\r\n                    result.success(seq);\r\n                }\r\n            }\r\n        }).onFailure(result::failure));\r\n    }\r\n\r\n    Future<Seq<T>> result() {\r\n        return result.future();\r\n    }\r\n}\r\n```"}}