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 <R> FastFuture<List<R>> xOf(int x, Runnable onComplete, FastFuture... futures) { // needs to use onComplete FastFuture xOf = new FastFuture(FinalPipeline.empty(), x); for (FastFuture next : futures) { AtomicInteger count = new AtomicInteger(0); next.onComplete( v -> { if (!count.compareAndSet(0, 1)) return; if (xOf.count.incrementAndGet() >= xOf.max.get()) { onComplete.run(); } }); } return xOf; }