Promises { @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull public static <T> Promise<T[]> toArray(@NotNull Class<T> type) { return Promise.of((T[]) Array.newInstance(type, 0)); }  @Contract(pure = true) @NotNull static Promise<T> timeout(@NotNull Duration delay, @NotNull Promise<T> promise); @Contract(pure = true) @NotNull static Promise<T> timeout(long delay, @NotNull Promise<T> promise); @Contract(pure = true) @NotNull static Promise<Void> delay(@NotNull Duration delay); @Contract(pure = true) @NotNull static Promise<Void> delay(long delayMillis); @Contract(pure = true) @NotNull static Promise<T> delay(@NotNull Duration delay, T value); @Contract(pure = true) @NotNull static Promise<T> delay(long delayMillis, T value); @Contract(pure = true) @NotNull static Promise<T> delay(@NotNull Duration delay, @NotNull Promise<T> promise); @Contract(pure = true) @NotNull static Promise<T> delay(long delayMillis, @NotNull Promise<T> promise); @Contract(pure = true) @NotNull static Promise<T> interval(@NotNull Duration interval, @NotNull Promise<T> promise); @Contract(pure = true) @NotNull static Promise<T> interval(long intervalMillis, @NotNull Promise<T> promise); @Contract(pure = true) @NotNull static Promise<Void> schedule(@NotNull Instant instant); @Contract(pure = true) @NotNull static Promise<Void> schedule(long timestamp); @Contract(pure = true) @NotNull static Promise<T> schedule(T value, @NotNull Instant instant); @Contract(pure = true) @NotNull static Promise<T> schedule(T value, long timestamp); @Contract(pure = true) @NotNull static Promise<T> schedule(@NotNull Promise<T> promise, @NotNull Instant instant); @Contract(pure = true) @NotNull static Promise<T> schedule(@NotNull Promise<T> promise, long timestamp); @Contract(pure = true) @NotNull static Promise<Void> all(); @Contract(pure = true) @NotNull static Promise<Void> all(@NotNull Promise<?> promise1); @Contract(pure = true) @NotNull static Promise<Void> all(@NotNull Promise<?> promise1, @NotNull Promise<?> promise2); @Contract(pure = true) @NotNull static Promise<Void> all(@NotNull Promise<?>... promises); @Contract(pure = true) @NotNull static Promise<Void> all(@NotNull Stream<? extends Promise<?>> promises); @Contract(pure = true) @NotNull static Promise<Void> all(@NotNull Iterable<? extends Promise<?>> promises); @Contract(pure = true) @NotNull static Promise<Void> all(@NotNull List<? extends Promise<?>> promises); @NotNull static Promise<Void> all(@NotNull Iterator<? extends Promise<?>> promises); static Promise<Void> allCompleted(@NotNull Iterator<? extends Promise<?>> promises); @Contract(pure = true) @NotNull static Promise<T> any(); @Contract(pure = true) @NotNull @SuppressWarnings("unchecked") static Promise<T> any(@NotNull Promise<? extends T> promise1); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<T> any(@NotNull Promise<? extends T> promise1, @NotNull Promise<? extends T> promise2); @Contract(pure = true) @NotNull @SafeVarargs static Promise<T> any(@NotNull Promise<? extends T>... promises); @Contract(pure = true) @NotNull static Promise<T> any(@NotNull Stream<? extends Promise<? extends T>> promises); @Contract(pure = true) @NotNull static Promise<T> any(@NotNull Iterable<? extends Promise<? extends T>> promises); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<T> any(@NotNull List<? extends Promise<? extends T>> promises); @NotNull static Promise<T> any(@NotNull Iterator<? extends Promise<? extends T>> promises); @NotNull static Promise<T> any(@NotNull Stream<? extends Promise<? extends T>> promises, @NotNull Consumer<T> cleanup); @NotNull static Promise<T> any(@NotNull Iterable<? extends Promise<? extends T>> promises, @NotNull Consumer<T> cleanup); @NotNull static Promise<T> any(@NotNull Iterator<? extends Promise<? extends T>> promises, @NotNull Consumer<T> cleanup); @Contract(pure = true) @NotNull static Promise<?> some(int number); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<List<T>> some(@NotNull Promise<? extends T> promise, int number); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<List<T>> some(@NotNull Promise<? extends T> promise1,
			@NotNull Promise<? extends T> promise2,
			int number); @Contract(pure = true) @NotNull static Promise<List<T>> some(@NotNull List<? extends Promise<? extends T>> promises, int number); @Contract(pure = true) @NotNull static Promise<List<T>> some(@NotNull Stream<? extends Promise<? extends T>> promises, int number); @Contract(pure = true) @NotNull static Promise<List<T>> some(@NotNull Iterable<? extends Promise<? extends T>> promises, int number); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<List<T>> some(@NotNull Iterator<? extends Promise<? extends T>> promises, int number); @Contract(pure = true) @NotNull static Promise<List<T>> toList(); @Contract(pure = true) @NotNull static Promise<List<T>> toList(@NotNull Promise<? extends T> promise1); @Contract(pure = true) @NotNull static Promise<List<T>> toList(@NotNull Promise<? extends T> promise1, @NotNull Promise<? extends T> promise2); @SafeVarargs @Contract(pure = true) @NotNull static Promise<List<T>> toList(@NotNull Promise<? extends T>... promises); @Contract(pure = true) @NotNull static Promise<List<T>> toList(@NotNull Stream<? extends Promise<? extends T>> promises); @Contract(pure = true) @NotNull @SuppressWarnings("unchecked") static Promise<List<T>> toList(@NotNull List<? extends Promise<? extends T>> promises); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<T[]> toArray(@NotNull Class<T> type); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<T[]> toArray(@NotNull Class<T> type, @NotNull Promise<? extends T> promise1); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<T[]> toArray(@NotNull Class<T> type, @NotNull Promise<? extends T> promise1, @NotNull Promise<? extends T> promise2); @SafeVarargs @Contract(pure = true) @NotNull static Promise<T[]> toArray(@NotNull Class<T> type, @NotNull Promise<? extends T>... promises); @Contract(pure = true) @NotNull static Promise<T[]> toArray(@NotNull Class<T> type, @NotNull Stream<? extends Promise<? extends T>> promises); @Contract(pure = true) @NotNull static Promise<T[]> toArray(@NotNull Class<T> type, @NotNull List<? extends Promise<? extends T>> promises); @Contract(pure = true) @NotNull static Promise<R> toTuple(@NotNull TupleConstructor1<T1, R> constructor, @NotNull Promise<? extends T1> promise1); @Contract(pure = true) @NotNull static Promise<R> toTuple(@NotNull TupleConstructor2<T1, T2, R> constructor,
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<R> toTuple(@NotNull TupleConstructor3<T1, T2, T3, R> constructor,
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2,
			@NotNull Promise<? extends T3> promise3); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<R> toTuple(@NotNull TupleConstructor4<T1, T2, T3, T4, R> constructor,
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2,
			@NotNull Promise<? extends T3> promise3,
			@NotNull Promise<? extends T4> promise4); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<R> toTuple(@NotNull TupleConstructor5<T1, T2, T3, T4, T5, R> constructor,
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2,
			@NotNull Promise<? extends T3> promise3,
			@NotNull Promise<? extends T4> promise4,
			@NotNull Promise<? extends T5> promise5); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<R> toTuple(@NotNull TupleConstructor6<T1, T2, T3, T4, T5, T6, R> constructor,
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2,
			@NotNull Promise<? extends T3> promise3,
			@NotNull Promise<? extends T4> promise4,
			@NotNull Promise<? extends T5> promise5,
			@NotNull Promise<? extends T6> promise6); @Contract(pure = true) @NotNull static Promise<Tuple1<T1>> toTuple(@NotNull Promise<? extends T1> promise1); @Contract(pure = true) @NotNull static Promise<Tuple2<T1, T2>> toTuple(@NotNull Promise<? extends T1> promise1, @NotNull Promise<? extends T2> promise2); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<Tuple3<T1, T2, T3>> toTuple(
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2,
			@NotNull Promise<? extends T3> promise3); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<Tuple4<T1, T2, T3, T4>> toTuple(
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2,
			@NotNull Promise<? extends T3> promise3,
			@NotNull Promise<? extends T4> promise4); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<Tuple5<T1, T2, T3, T4, T5>> toTuple(
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2,
			@NotNull Promise<? extends T3> promise3,
			@NotNull Promise<? extends T4> promise4,
			@NotNull Promise<? extends T5> promise5); @SuppressWarnings("unchecked") @Contract(pure = true) @NotNull static Promise<Tuple6<T1, T2, T3, T4, T5, T6>> toTuple(
			@NotNull Promise<? extends T1> promise1,
			@NotNull Promise<? extends T2> promise2,
			@NotNull Promise<? extends T3> promise3,
			@NotNull Promise<? extends T4> promise4,
			@NotNull Promise<? extends T5> promise5,
			@NotNull Promise<? extends T6> promise6); @Contract(pure = true) @NotNull static Function<T, Promise<R>> mapTuple(@NotNull TupleConstructor1<R1, R> constructor,
			@NotNull Function<? super T, T1> getter1, Function<T1, ? extends Promise<R1>> fn1); @Contract(pure = true) @NotNull static Function<T, Promise<R>> mapTuple(@NotNull TupleConstructor2<R1, R2, R> constructor,
			@NotNull Function<? super T, T1> getter1, Function<T1, ? extends Promise<R1>> fn1,
			@NotNull Function<? super T, T2> getter2, Function<T2, ? extends Promise<R2>> fn2); @Contract(pure = true) @NotNull static Function<T, Promise<R>> mapTuple(@NotNull TupleConstructor3<R1, R2, R3, R> constructor,
			@NotNull Function<? super T, T1> getter1, Function<T1, ? extends Promise<R1>> fn1,
			@NotNull Function<? super T, T2> getter2, Function<T2, ? extends Promise<R2>> fn2,
			@NotNull Function<? super T, T3> getter3, Function<T3, ? extends Promise<R3>> fn3); @Contract(pure = true) @NotNull static Function<T, Promise<R>> mapTuple(@NotNull TupleConstructor4<R1, R2, R3, R4, R> constructor,
			@NotNull Function<? super T, T1> getter1, Function<T1, ? extends Promise<R1>> fn1,
			@NotNull Function<? super T, T2> getter2, Function<T2, ? extends Promise<R2>> fn2,
			@NotNull Function<? super T, T3> getter3, Function<T3, ? extends Promise<R3>> fn3,
			@NotNull Function<? super T, T4> getter4, Function<T4, ? extends Promise<R4>> fn4); @Contract(pure = true) @NotNull static Function<T, Promise<R>> mapTuple(@NotNull TupleConstructor5<R1, R2, R3, R4, R5, R> constructor,
			@NotNull Function<? super T, T1> getter1, Function<T1, ? extends Promise<R1>> fn1,
			@NotNull Function<? super T, T2> getter2, Function<T2, ? extends Promise<R2>> fn2,
			@NotNull Function<? super T, T3> getter3, Function<T3, ? extends Promise<R3>> fn3,
			@NotNull Function<? super T, T4> getter4, Function<T4, ? extends Promise<R4>> fn4,
			@NotNull Function<? super T, T5> getter5, Function<T5, ? extends Promise<R5>> fn5); @Contract(pure = true) @NotNull static Function<T, Promise<R>> mapTuple(@NotNull TupleConstructor6<R1, R2, R3, R4, R5, R6, R> constructor,
			@NotNull Function<? super T, T1> getter1, Function<T1, ? extends Promise<R1>> fn1,
			@NotNull Function<? super T, T2> getter2, Function<T2, ? extends Promise<R2>> fn2,
			@NotNull Function<? super T, T3> getter3, Function<T3, ? extends Promise<R3>> fn3,
			@NotNull Function<? super T, T4> getter4, Function<T4, ? extends Promise<R4>> fn4,
			@NotNull Function<? super T, T5> getter5, Function<T5, ? extends Promise<R5>> fn5,
			@NotNull Function<? super T, T6> getter6, Function<T6, ? extends Promise<R6>> fn6); @NotNull static Promise<Void> sequence(); @NotNull static Promise<Void> sequence(@NotNull AsyncSupplier<Void> promise); @NotNull static Promise<Void> sequence(@NotNull AsyncSupplier<Void> promise1, @NotNull AsyncSupplier<Void> promise2); @NotNull @SafeVarargs static Promise<Void> sequence(@NotNull AsyncSupplier<Void>... promises); @NotNull static Promise<Void> sequence(@NotNull Iterable<? extends AsyncSupplier<Void>> promises); @NotNull static Promise<Void> sequence(@NotNull Stream<? extends AsyncSupplier<Void>> promises); @NotNull static Promise<Void> sequence(@NotNull Iterator<? extends Promise<Void>> promises); @NotNull @SafeVarargs static Promise<T> firstSuccessful(AsyncSupplier<? extends T>... promises); @NotNull static Promise<T> firstSuccessful(@NotNull Iterable<? extends AsyncSupplier<? extends T>> promises); @NotNull static Promise<T> firstSuccessful(@NotNull Stream<? extends AsyncSupplier<? extends T>> promises); @NotNull static Promise<T> firstSuccessful(@NotNull Iterator<? extends Promise<? extends T>> promises); @NotNull @SafeVarargs static Promise<T> first(@NotNull BiPredicate<? super T, ? super Throwable> predicate,
			@NotNull AsyncSupplier<? extends T>... promises); @NotNull static Promise<T> first(@NotNull BiPredicate<? super T, ? super Throwable> predicate,
			@NotNull Iterable<? extends AsyncSupplier<? extends T>> promises); @NotNull static Promise<T> first(@NotNull BiPredicate<? super T, ? super Throwable> predicate,
			@NotNull Stream<? extends AsyncSupplier<? extends T>> promises); @NotNull static Promise<T> first(@NotNull BiPredicate<? super T, ? super Throwable> predicate,
			@NotNull Iterator<? extends Promise<? extends T>> promises); @Contract(value = " -> new", pure = true) @NotNull static BiPredicate<T, Throwable> isResult(); @Contract(value = " -> new", pure = true) @NotNull static BiPredicate<T, Throwable> isError(); @NotNull static Promise<Void> repeat(@NotNull Supplier<Promise<Void>> supplier); static Promise<T> loop(@Nullable T seed, @NotNull Predicate<T> loopCondition, @NotNull Function<T, Promise<T>> next); static Promise<T> until(@Nullable T seed, @NotNull Function<T, Promise<T>> next, @NotNull Predicate<T> breakCondition); static Promise<T> retry(AsyncSupplier<T> asyncSupplier); static Promise<T> retry(AsyncSupplier<T> asyncSupplier, BiPredicate<T, Throwable> breakCondition); static Promise<T> retry(AsyncSupplier<T> asyncSupplier, @NotNull RetryPolicy<?> retryPolicy); static Promise<T> retry(AsyncSupplier<T> asyncSupplier, BiPredicate<T, Throwable> breakCondition, @NotNull RetryPolicy<?> retryPolicy); @SuppressWarnings("unchecked") @NotNull static Iterator<Promise<T>> asPromises(@NotNull Iterator<? extends AsyncSupplier<? extends T>> tasks); static Iterator<Promise<T>> asPromises(@NotNull Stream<? extends AsyncSupplier<? extends T>> tasks); static Iterator<Promise<T>> asPromises(@NotNull Iterable<? extends AsyncSupplier<? extends T>> tasks); @SafeVarargs static Iterator<Promise<T>> asPromises(@NotNull AsyncSupplier<? extends T>... tasks); static Promise<R> reduce(@NotNull Collector<T, A, R> collector, int maxCalls,
			@NotNull Iterator<Promise<T>> promises); static Promise<R> reduce(@NotNull Iterator<Promise<T>> promises, int maxCalls,
			A accumulator,
			@NotNull BiConsumer<A, T> consumer,
			@NotNull Function<A, R> finisher); static Promise<R> reduceEx(@NotNull Iterator<Promise<T>> promises, @NotNull ToIntFunction<A> maxCalls,
			A accumulator,
			@NotNull BiFunction<A, Try<T>, @Nullable Try<R>> consumer,
			@NotNull Function<A, @NotNull Try<R>> finisher,
			@Nullable Consumer<T> recycler); @Contract(pure = true) @NotNull static Function<T, Promise<R>> coalesce(@NotNull Supplier<A> argumentAccumulatorSupplier, @NotNull BiConsumer<A, T> argumentAccumulatorFn,
			@NotNull Function<A, Promise<R>> fn); static final AsyncTimeoutException TIMEOUT_EXCEPTION; }
@Test public void varargsToArrayDoubleTest() { Integer[] array = await(toArray(Integer.class, Promise.of(321), Promise.of(322), Promise.of(323))); assertEquals(3, array.length); assertEquals(new Integer(321), array[0]); assertEquals(new Integer(322), array[1]); assertEquals(new Integer(323), array[2]); }
@Test public void streamToArrayDoubleTest() { Integer[] array = await(toArray(Integer.class, Stream.of(Promise.of(321), Promise.of(322), Promise.of(323)))); assertEquals(3, array.length); assertEquals(new Integer(321), array[0]); assertEquals(new Integer(322), array[1]); assertEquals(new Integer(323), array[2]); }
@Test public void listToArrayDoubleTest() { Integer[] array = await(toArray(Integer.class, asList(Promise.of(321), Promise.of(322), Promise.of(323)))); assertEquals(3, array.length); assertEquals(new Integer(321), array[0]); assertEquals(new Integer(322), array[1]); assertEquals(new Integer(323), array[2]); }
@Test public void toArrayEmptyTest() { Object[] array = await(toArray(Object.class)); assertEquals(0, array.length); }
@Test public void toArraySingleTest() { Integer[] array = await(toArray(Integer.class, Promise.of(321))); assertEquals(1, array.length); assertEquals(new Integer(321), array[0]); }
@Test public void arraytoArrayDoubleTest() { Integer[] array = await(toArray(Integer.class, Promise.of(321), Promise.of(322))); assertEquals(2, array.length); assertEquals(new Integer(321), array[0]); assertEquals(new Integer(322), array[1]); }