Skip to content

Conversation

@dfa1
Copy link
Contributor

@dfa1 dfa1 commented Nov 20, 2022

@bbakerman @andimarek hello :)

I'm trying to reduce some duplications in Async class. What do you think?

Async.each(list, cfFactory) with factory was delegating back to Async.each(futures),
allocating some extra objects (CompletableFuture + List). The current implementation simply delegates
to the new Async.CombinedBuilder.
});
return overallResult;
public static <U> CompletableFuture<List<U>> each(List<CompletableFuture<U>> futures) { // TODO: used only in tests now
CombinedBuilder<U> overall = ofExpectedSize(futures.size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also created a method that produced a build of the right size in one call

CombinedBuilder<U> overall = fromList(futures);

There is no need to add them all one by one outside that method.

You can do the same code as here inside the fromList method say

Copy link
Contributor Author

@dfa1 dfa1 Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but I stopped for 2 reasons:

  • that will defeat the idea of the CombinedBuilder (i.e. avoid List -> array conversion/allocations)
  • this method is used only for tests now... and since it is @Internal, we should be fine no?

@bbakerman bbakerman added this to the 20.0 milestone Nov 22, 2022
@bbakerman bbakerman merged commit eec55e5 into graphql-java:master Nov 22, 2022
@dfa1 dfa1 deleted the improving-async branch November 23, 2022 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants