Skip to content

Instantly share code, notes, and snippets.

@isopropylcyanide
Created March 14, 2021 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isopropylcyanide/c806dece64b7c1fe0a13831c689bc76c to your computer and use it in GitHub Desktop.
Save isopropylcyanide/c806dece64b7c1fe0a13831c689bc76c to your computer and use it in GitHub Desktop.
public interface ConcurrentWorkExecutor {
/**
* Splits a work iterable and submits each task into an executor where the task input is obtained by
* applying a mapper function. The intermediate non null results are joined until a {@code size} number
* of results are obtained post which they are collected using a custom user defined collector.
*
* @param size the number of results to wait for
* @param iterable the work represented as an iterable
* @param mapper the transformation of individual item U within the iterable to a result T
* @param collector the collection of T results obtained into a custom collector of type V
* @return an object of type V which is obtained after collection of intermediate T type results
* @implNote - If all intermediate results are required before collecting the final result, {@code size}
* must be equal to the number of items represented by the iterable
*/
<T, U, V> V splitJoin(int size,
Iterable<U> iterable,
Function<U, T> mapper,
Collector<T, ?, V> collector
) throws ExecutionException, InterruptedException;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment