Skip to content

Instantly share code, notes, and snippets.

@tifletcher
Created November 10, 2015 22:32
Show Gist options
  • Save tifletcher/c78d4b258919a5186940 to your computer and use it in GitHub Desktop.
Save tifletcher/c78d4b258919a5186940 to your computer and use it in GitHub Desktop.
final List<Future<UserProfile>> futures = userIds.stream().distinct().filter(Objects::nonNull)
.map(id -> new GetUserProfileCommand(registry, authToken, id, roleMap).queue())
.collect(Collectors.toList());
return futures.stream().parallel()
.map(f -> {
try {
return f.get();
} catch (InterruptedException | ExecutionException e) {
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toConcurrentMap(UserProfile::getUserId, profile -> profile));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment