@SuppressWarnings("unchecked") private <U, V> V execute(U inputParameter, ProcessDescription<U, V> processDescription, Executor executorService) throws InterruptedException, ExecutionException { if (processDescription.getThreadType().equals(ThreadType.EXECUTOR)) { FutureTask<V> task = new FutureTask<V>(() -> { return processDescription.getFunction().apply(inputParameter); }); executorService.execute(task); return task.get(); } else { return ConcurrentUtils.runCallableAndWait(() -> { return processDescription.getFunction().apply(inputParameter); }); } }
public <V> ProcessChain<V> addFunction(Function<T, V> function, ThreadType type) { processes.add(new ProcessDescription<T, V>(function, type)); return new ProcessChain<V>(executorService, processes); }