private void set(Supplier<T> result, int index) { try { Object current = result.get(); final Object use = current; if (index < pipeline.functions.length) { Function op = pipeline.functions[index]; this.pipeline.executors[index].execute( () -> { set(() -> (T) op.apply(use), index + 1); }); return; } this.result.lazySet(current); done(); } catch (Throwable t) { if (t instanceof CompletedException) { if (this.doFinally != null) doFinally.accept(this); } completeExceptionally(t); } }
public void set(T result) { try { final Object use = result; if (pipeline == null || pipeline.functions.length == 0) { this.result.lazySet(use); done(); return; } Function op = pipeline.functions[0]; if (this.pipeline.executors[0] != null) { this.pipeline.executors[0].execute( () -> { set(() -> (T) op.apply(use), 1); }); } else { set(() -> (T) op.apply(use), 1); } } catch (Throwable t) { completeExceptionally(t); } }
public static <R> FastFuture<List<R>> anyOf(FastFuture... futures) { FastFuture anyOf = new FastFuture(); for (FastFuture next : futures) { next.onComplete( v -> { anyOf.result.lazySet(true); anyOf.done(); }); } return anyOf; }
public static <T> FastFuture<T> completedFuture(T value) { FastFuture<T> f = new FastFuture(); f.result.lazySet(value); f.done = true; return f; }