Class Promises


  • public final class Promises
    extends Object
    Allows to manage multiple Promises.
    • Constructor Detail

      • Promises

        public Promises()
    • Method Detail

      • timeout

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> timeout​(long delay,
                                                      @NotNull
                                                      @NotNull Promise<T> promise)
        Waits until the delay passes and if the Promise is still not complete, tries to complete it with TIMEOUT_EXCEPTION.
        Parameters:
        delay - time of delay
        promise - the Promise to be tracked
        Returns:
        Promise
      • delay

        @Contract(pure=true)
        @NotNull
        public static @NotNull Promise<Void> delay​(@NotNull
                                                   @NotNull Duration delay)
      • delay

        @Contract(pure=true)
        @NotNull
        public static @NotNull Promise<Void> delay​(long delayMillis)
      • delay

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> delay​(@NotNull
                                                    @NotNull Duration delay,
                                                    T value)
      • delay

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> delay​(long delayMillis,
                                                    T value)
      • delay

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> delay​(long delayMillis,
                                                    @NotNull
                                                    @NotNull Promise<T> promise)
        Delays completion of provided promise for the defined period of time.
        Parameters:
        delayMillis - delay in millis
        promise - the Promise to be delayed
        Returns:
        completed Promise
      • interval

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> interval​(@NotNull
                                                       @NotNull Duration interval,
                                                       @NotNull
                                                       @NotNull Promise<T> promise)
      • interval

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> interval​(long intervalMillis,
                                                       @NotNull
                                                       @NotNull Promise<T> promise)
      • schedule

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> schedule​(T value,
                                                       long timestamp)
        See Also:
        schedule(Promise, long)
      • schedule

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> schedule​(@NotNull
                                                       @NotNull Promise<T> promise,
                                                       long timestamp)
        Schedules completion of the Promise so that it will be completed after the timestamp even if its operations were completed earlier.
      • all

        @Contract(pure=true)
        @NotNull
        public static @NotNull Promise<Void> all()
        See Also:
        all(List)
      • all

        @Contract(pure=true)
        @NotNull
        public static @NotNull Promise<Void> all​(@NotNull
                                                 @NotNull Promise<?> promise1)
        See Also:
        all(List)
      • all

        @Contract(pure=true)
        @NotNull
        public static @NotNull Promise<Void> all​(@NotNull
                                                 @NotNull Promise<?> promise1,
                                                 @NotNull
                                                 @NotNull Promise<?> promise2)
        Optimized for 2 promises.
        See Also:
        all(List)
      • all

        @Contract(pure=true)
        @NotNull
        public static @NotNull Promise<Void> all​(@NotNull
                                                 @NotNull Promise<?>... promises)
        See Also:
        all(List)
      • all

        @Contract(pure=true)
        @NotNull
        public static @NotNull Promise<Void> all​(@NotNull
                                                 @NotNull List<? extends Promise<?>> promises)
        Returns a Promise that completes when all of the promises are completed.
      • all

        @NotNull
        public static @NotNull Promise<Void> all​(@NotNull
                                                 @NotNull Iterator<? extends Promise<?>> promises)
        Returns Promise that completes when all of the promises are completed. If at least one of the promises completes exceptionally, a CompleteExceptionallyPromise will be returned.
      • any

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull Promise<? extends T> promise1)
        See Also:
        any(Iterator)
      • any

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull Promise<? extends T> promise1,
                                                  @NotNull
                                                  @NotNull Promise<? extends T> promise2)
        Optimized for 2 promises.
        See Also:
        any(Iterator)
      • any

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull List<? extends Promise<? extends T>> promises)
        See Also:
        any(Iterator)
      • any

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull Stream<? extends Promise<? extends T>> promises)
        See Also:
        any(Iterator)
      • any

        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull Iterator<? extends Promise<? extends T>> promises)
      • any

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull BiPredicate<T,​Throwable> predicate,
                                                  @NotNull
                                                  @NotNull Promise<? extends T> promise1)
      • any

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull BiPredicate<T,​Throwable> predicate,
                                                  @NotNull
                                                  @NotNull Promise<? extends T> promise1,
                                                  @NotNull
                                                  @NotNull Promise<? extends T> promise2)
      • any

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull BiPredicate<T,​Throwable> predicate,
                                                  @NotNull
                                                  @NotNull Stream<? extends Promise<? extends T>> promises)
      • any

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T> any​(@NotNull
                                                  @NotNull BiPredicate<T,​Throwable> predicate,
                                                  @NotNull
                                                  @NotNull List<? extends Promise<? extends T>> promises)
      • toList

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<List<T>> toList()
        Returns a successfully completed Promise with an empty list as the result.
      • toList

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<List<T>> toList​(@NotNull
                                                           @NotNull Promise<? extends T> promise1)
        Returns a completed Promise with a result wrapped in List.
      • toList

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<List<T>> toList​(@NotNull
                                                           @NotNull Promise<? extends T> promise1,
                                                           @NotNull
                                                           @NotNull Promise<? extends T> promise2)
        Returns Promise with a list of promise1 and promise2 results.
      • toList

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<List<T>> toList​(@NotNull
                                                           @NotNull List<? extends Promise<? extends T>> promises)
        Reduces list of Promises into Promise<List>.
      • toList

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<List<T>> toList​(@NotNull
                                                           @NotNull Stream<? extends Promise<? extends T>> promises)
        See Also:
        toList(List)
      • toArray

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T[]> toArray​(@NotNull
                                                        @NotNull Class<T> type)
        Returns an array of provided type and length 0 wrapped in Promise.
      • toArray

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T[]> toArray​(@NotNull
                                                        @NotNull Class<T> type,
                                                        @NotNull
                                                        @NotNull Promise<? extends T> promise1)
        Returns an array with promise1 result.
      • toArray

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T[]> toArray​(@NotNull
                                                        @NotNull Class<T> type,
                                                        @NotNull
                                                        @NotNull Promise<? extends T> promise1,
                                                        @NotNull
                                                        @NotNull Promise<? extends T> promise2)
        Returns an array with promise1 and promise2 results.
      • toArray

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T[]> toArray​(@NotNull
                                                        @NotNull Class<T> type,
                                                        @NotNull
                                                        @NotNull List<? extends Promise<? extends T>> promises)
        Reduces promises into Promise<Array>
      • toArray

        @Contract(pure=true)
        @NotNull
        public static <T> @NotNull Promise<T[]> toArray​(@NotNull
                                                        @NotNull Class<T> type,
                                                        @NotNull
                                                        @NotNull Stream<? extends Promise<? extends T>> promises)
        See Also:
        toArray(Class, List)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​R> @NotNull Promise<R> toTuple​(@NotNull
                                                               @NotNull io.activej.common.tuple.TupleConstructor1<T1,​R> constructor,
                                                               @NotNull
                                                               @NotNull Promise<? extends T1> promise1)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​R> @NotNull Promise<R> toTuple​(@NotNull
                                                                        @NotNull io.activej.common.tuple.TupleConstructor2<T1,​T2,​R> constructor,
                                                                        @NotNull
                                                                        @NotNull Promise<? extends T1> promise1,
                                                                        @NotNull
                                                                        @NotNull Promise<? extends T2> promise2)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​T3,​R> @NotNull Promise<R> toTuple​(@NotNull
                                                                                 @NotNull io.activej.common.tuple.TupleConstructor3<T1,​T2,​T3,​R> constructor,
                                                                                 @NotNull
                                                                                 @NotNull Promise<? extends T1> promise1,
                                                                                 @NotNull
                                                                                 @NotNull Promise<? extends T2> promise2,
                                                                                 @NotNull
                                                                                 @NotNull Promise<? extends T3> promise3)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​T3,​T4,​R> @NotNull Promise<R> toTuple​(@NotNull
                                                                                          @NotNull io.activej.common.tuple.TupleConstructor4<T1,​T2,​T3,​T4,​R> constructor,
                                                                                          @NotNull
                                                                                          @NotNull Promise<? extends T1> promise1,
                                                                                          @NotNull
                                                                                          @NotNull Promise<? extends T2> promise2,
                                                                                          @NotNull
                                                                                          @NotNull Promise<? extends T3> promise3,
                                                                                          @NotNull
                                                                                          @NotNull Promise<? extends T4> promise4)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​T3,​T4,​T5,​R> @NotNull Promise<R> toTuple​(@NotNull
                                                                                                   @NotNull io.activej.common.tuple.TupleConstructor5<T1,​T2,​T3,​T4,​T5,​R> constructor,
                                                                                                   @NotNull
                                                                                                   @NotNull Promise<? extends T1> promise1,
                                                                                                   @NotNull
                                                                                                   @NotNull Promise<? extends T2> promise2,
                                                                                                   @NotNull
                                                                                                   @NotNull Promise<? extends T3> promise3,
                                                                                                   @NotNull
                                                                                                   @NotNull Promise<? extends T4> promise4,
                                                                                                   @NotNull
                                                                                                   @NotNull Promise<? extends T5> promise5)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​T3,​T4,​T5,​T6,​R> @NotNull Promise<R> toTuple​(@NotNull
                                                                                                            @NotNull io.activej.common.tuple.TupleConstructor6<T1,​T2,​T3,​T4,​T5,​T6,​R> constructor,
                                                                                                            @NotNull
                                                                                                            @NotNull Promise<? extends T1> promise1,
                                                                                                            @NotNull
                                                                                                            @NotNull Promise<? extends T2> promise2,
                                                                                                            @NotNull
                                                                                                            @NotNull Promise<? extends T3> promise3,
                                                                                                            @NotNull
                                                                                                            @NotNull Promise<? extends T4> promise4,
                                                                                                            @NotNull
                                                                                                            @NotNull Promise<? extends T5> promise5,
                                                                                                            @NotNull
                                                                                                            @NotNull Promise<? extends T6> promise6)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1> @NotNull Promise<io.activej.common.tuple.Tuple1<T1>> toTuple​(@NotNull
                                                                                        @NotNull Promise<? extends T1> promise1)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2> @NotNull Promise<io.activej.common.tuple.Tuple2<T1,​T2>> toTuple​(@NotNull
                                                                                                          @NotNull Promise<? extends T1> promise1,
                                                                                                          @NotNull
                                                                                                          @NotNull Promise<? extends T2> promise2)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​T3> @NotNull Promise<io.activej.common.tuple.Tuple3<T1,​T2,​T3>> toTuple​(@NotNull
                                                                                                                            @NotNull Promise<? extends T1> promise1,
                                                                                                                            @NotNull
                                                                                                                            @NotNull Promise<? extends T2> promise2,
                                                                                                                            @NotNull
                                                                                                                            @NotNull Promise<? extends T3> promise3)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​T3,​T4> @NotNull Promise<io.activej.common.tuple.Tuple4<T1,​T2,​T3,​T4>> toTuple​(@NotNull
                                                                                                                                              @NotNull Promise<? extends T1> promise1,
                                                                                                                                              @NotNull
                                                                                                                                              @NotNull Promise<? extends T2> promise2,
                                                                                                                                              @NotNull
                                                                                                                                              @NotNull Promise<? extends T3> promise3,
                                                                                                                                              @NotNull
                                                                                                                                              @NotNull Promise<? extends T4> promise4)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​T3,​T4,​T5> @NotNull Promise<io.activej.common.tuple.Tuple5<T1,​T2,​T3,​T4,​T5>> toTuple​(@NotNull
                                                                                                                                                                @NotNull Promise<? extends T1> promise1,
                                                                                                                                                                @NotNull
                                                                                                                                                                @NotNull Promise<? extends T2> promise2,
                                                                                                                                                                @NotNull
                                                                                                                                                                @NotNull Promise<? extends T3> promise3,
                                                                                                                                                                @NotNull
                                                                                                                                                                @NotNull Promise<? extends T4> promise4,
                                                                                                                                                                @NotNull
                                                                                                                                                                @NotNull Promise<? extends T5> promise5)
      • toTuple

        @Contract(pure=true)
        @NotNull
        public static <T1,​T2,​T3,​T4,​T5,​T6> @NotNull Promise<io.activej.common.tuple.Tuple6<T1,​T2,​T3,​T4,​T5,​T6>> toTuple​(@NotNull
                                                                                                                                                                                  @NotNull Promise<? extends T1> promise1,
                                                                                                                                                                                  @NotNull
                                                                                                                                                                                  @NotNull Promise<? extends T2> promise2,
                                                                                                                                                                                  @NotNull
                                                                                                                                                                                  @NotNull Promise<? extends T3> promise3,
                                                                                                                                                                                  @NotNull
                                                                                                                                                                                  @NotNull Promise<? extends T4> promise4,
                                                                                                                                                                                  @NotNull
                                                                                                                                                                                  @NotNull Promise<? extends T5> promise5,
                                                                                                                                                                                  @NotNull
                                                                                                                                                                                  @NotNull Promise<? extends T6> promise6)
      • mapTuple

        @Contract(pure=true)
        @NotNull
        public static <T,​T1,​R,​R1> @NotNull Function<T,​Promise<R>> mapTuple​(@NotNull
                                                                                                   @NotNull io.activej.common.tuple.TupleConstructor1<R1,​R> constructor,
                                                                                                   @NotNull
                                                                                                   @NotNull Function<? super T,​T1> getter1,
                                                                                                   Function<T1,​? extends Promise<R1>> fn1)
      • mapTuple

        @Contract(pure=true)
        @NotNull
        public static <T,​T1,​T2,​R,​R1,​R2> @NotNull Function<T,​Promise<R>> mapTuple​(@NotNull
                                                                                                                     @NotNull io.activej.common.tuple.TupleConstructor2<R1,​R2,​R> constructor,
                                                                                                                     @NotNull
                                                                                                                     @NotNull Function<? super T,​T1> getter1,
                                                                                                                     Function<T1,​? extends Promise<R1>> fn1,
                                                                                                                     @NotNull
                                                                                                                     @NotNull Function<? super T,​T2> getter2,
                                                                                                                     Function<T2,​? extends Promise<R2>> fn2)
      • mapTuple

        @Contract(pure=true)
        @NotNull
        public static <T,​T1,​T2,​T3,​R,​R1,​R2,​R3> @NotNull Function<T,​Promise<R>> mapTuple​(@NotNull
                                                                                                                                       @NotNull io.activej.common.tuple.TupleConstructor3<R1,​R2,​R3,​R> constructor,
                                                                                                                                       @NotNull
                                                                                                                                       @NotNull Function<? super T,​T1> getter1,
                                                                                                                                       Function<T1,​? extends Promise<R1>> fn1,
                                                                                                                                       @NotNull
                                                                                                                                       @NotNull Function<? super T,​T2> getter2,
                                                                                                                                       Function<T2,​? extends Promise<R2>> fn2,
                                                                                                                                       @NotNull
                                                                                                                                       @NotNull Function<? super T,​T3> getter3,
                                                                                                                                       Function<T3,​? extends Promise<R3>> fn3)
      • mapTuple

        @Contract(pure=true)
        @NotNull
        public static <T,​T1,​T2,​T3,​T4,​R,​R1,​R2,​R3,​R4> @NotNull Function<T,​Promise<R>> mapTuple​(@NotNull
                                                                                                                                                         @NotNull io.activej.common.tuple.TupleConstructor4<R1,​R2,​R3,​R4,​R> constructor,
                                                                                                                                                         @NotNull
                                                                                                                                                         @NotNull Function<? super T,​T1> getter1,
                                                                                                                                                         Function<T1,​? extends Promise<R1>> fn1,
                                                                                                                                                         @NotNull
                                                                                                                                                         @NotNull Function<? super T,​T2> getter2,
                                                                                                                                                         Function<T2,​? extends Promise<R2>> fn2,
                                                                                                                                                         @NotNull
                                                                                                                                                         @NotNull Function<? super T,​T3> getter3,
                                                                                                                                                         Function<T3,​? extends Promise<R3>> fn3,
                                                                                                                                                         @NotNull
                                                                                                                                                         @NotNull Function<? super T,​T4> getter4,
                                                                                                                                                         Function<T4,​? extends Promise<R4>> fn4)
      • mapTuple

        @Contract(pure=true)
        @NotNull
        public static <T,​T1,​T2,​T3,​T4,​T5,​R,​R1,​R2,​R3,​R4,​R5> @NotNull Function<T,​Promise<R>> mapTuple​(@NotNull
                                                                                                                                                                           @NotNull io.activej.common.tuple.TupleConstructor5<R1,​R2,​R3,​R4,​R5,​R> constructor,
                                                                                                                                                                           @NotNull
                                                                                                                                                                           @NotNull Function<? super T,​T1> getter1,
                                                                                                                                                                           Function<T1,​? extends Promise<R1>> fn1,
                                                                                                                                                                           @NotNull
                                                                                                                                                                           @NotNull Function<? super T,​T2> getter2,
                                                                                                                                                                           Function<T2,​? extends Promise<R2>> fn2,
                                                                                                                                                                           @NotNull
                                                                                                                                                                           @NotNull Function<? super T,​T3> getter3,
                                                                                                                                                                           Function<T3,​? extends Promise<R3>> fn3,
                                                                                                                                                                           @NotNull
                                                                                                                                                                           @NotNull Function<? super T,​T4> getter4,
                                                                                                                                                                           Function<T4,​? extends Promise<R4>> fn4,
                                                                                                                                                                           @NotNull
                                                                                                                                                                           @NotNull Function<? super T,​T5> getter5,
                                                                                                                                                                           Function<T5,​? extends Promise<R5>> fn5)
      • mapTuple

        @Contract(pure=true)
        @NotNull
        public static <T,​T1,​T2,​T3,​T4,​T5,​T6,​R,​R1,​R2,​R3,​R4,​R5,​R6> @NotNull Function<T,​Promise<R>> mapTuple​(@NotNull
                                                                                                                                                                                             @NotNull io.activej.common.tuple.TupleConstructor6<R1,​R2,​R3,​R4,​R5,​R6,​R> constructor,
                                                                                                                                                                                             @NotNull
                                                                                                                                                                                             @NotNull Function<? super T,​T1> getter1,
                                                                                                                                                                                             Function<T1,​? extends Promise<R1>> fn1,
                                                                                                                                                                                             @NotNull
                                                                                                                                                                                             @NotNull Function<? super T,​T2> getter2,
                                                                                                                                                                                             Function<T2,​? extends Promise<R2>> fn2,
                                                                                                                                                                                             @NotNull
                                                                                                                                                                                             @NotNull Function<? super T,​T3> getter3,
                                                                                                                                                                                             Function<T3,​? extends Promise<R3>> fn3,
                                                                                                                                                                                             @NotNull
                                                                                                                                                                                             @NotNull Function<? super T,​T4> getter4,
                                                                                                                                                                                             Function<T4,​? extends Promise<R4>> fn4,
                                                                                                                                                                                             @NotNull
                                                                                                                                                                                             @NotNull Function<? super T,​T5> getter5,
                                                                                                                                                                                             Function<T5,​? extends Promise<R5>> fn5,
                                                                                                                                                                                             @NotNull
                                                                                                                                                                                             @NotNull Function<? super T,​T6> getter6,
                                                                                                                                                                                             Function<T6,​? extends Promise<R6>> fn6)
      • sequence

        @NotNull
        public static @NotNull Promise<Void> sequence​(@NotNull
                                                      @NotNull AsyncSupplier<Void> promise)
        Gets Promise from provided AsyncSupplier, waits until it completes and than returns a Promise<Void>
      • sequence

        @NotNull
        public static @NotNull Promise<Void> sequence​(@NotNull
                                                      @NotNull AsyncSupplier<Void> promise1,
                                                      @NotNull
                                                      @NotNull AsyncSupplier<Void> promise2)
        Gets Promises from provided AsyncSuppliers, end executes them consequently, discarding their results.
      • sequence

        @NotNull
        public static @NotNull Promise<Void> sequence​(@NotNull
                                                      @NotNull Iterator<? extends Promise<Void>> promises)
        Calls every Promise from promises in sequence and discards their results.Returns a SettablePromise with null result as a marker when all of the promises are completed.
        Returns:
        Promise that completes when all promises are completed
      • first

        @NotNull
        public static <T> @NotNull Promise<T> first​(@NotNull
                                                    @NotNull BiPredicate<? super T,​? super Throwable> predicate,
                                                    @NotNull
                                                    @NotNull Iterator<? extends Promise<? extends T>> promises)
        Parameters:
        predicate - filters results, consumes result of Promise
        Returns:
        first completed result of Promise that satisfies predicate
      • isResult

        @NotNull
        public static <T> @NotNull BiPredicate<T,​Throwable> isResult()
        Returns a BiPredicate which checks if Promise wasn't completed exceptionally.
      • isError

        @NotNull
        public static <T> @NotNull BiPredicate<T,​Throwable> isError()
        Returns a BiPredicate which checks if Promise was completed with an exception.
      • repeat

        @NotNull
        public static @NotNull Promise<Void> repeat​(@NotNull
                                                    @NotNull Supplier<Promise<Boolean>> supplier)
        Repeats the operations of provided supplier infinitely, until one of the Promises completes exceptionally.
      • loop

        public static <T> Promise<T> loop​(@Nullable
                                          T seed,
                                          @NotNull
                                          @NotNull Predicate<T> loopCondition,
                                          @NotNull
                                          @NotNull Function<T,​Promise<T>> next)
        Repeats provided Function until can pass Predicate test. Resembles a simple Java for() loop but with async capabilities.
        Parameters:
        seed - start value
        loopCondition - a boolean function which checks if this loop can continue
        next - a function applied to the seed, returns Promise
        Returns:
        SettablePromise with null result if it was completed successfully, otherwise returns a SettablePromise with an exception. In both situations returned Promise is a marker of completion of the loop.
      • until

        public static <T> Promise<T> until​(@Nullable
                                           T seed,
                                           @NotNull
                                           @NotNull Function<T,​Promise<T>> next,
                                           @NotNull
                                           @NotNull Predicate<T> breakCondition)
      • reduce

        public static <T,​A,​R> Promise<R> reduce​(@NotNull
                                                            @NotNull Collector<T,​A,​R> collector,
                                                            int maxCalls,
                                                            @NotNull
                                                            @NotNull Iterator<Promise<T>> promises)
        Allows to asynchronously reduce Iterator of Promises into a Promise with the help of Collector. You can control the amount of concurrently running Promise.

        This method is universal and allows to implement app-specific logic.

        Type Parameters:
        T - type of input elements for this operation
        A - mutable accumulation type of the operation
        R - the result type of the operation
        Parameters:
        collector - mutable reduction operation that accumulates input elements into a mutable result container
        maxCalls - max amount of concurrently running Promises
        promises - Iterable of Promises
        Returns:
        a Promise which wraps the accumulated result of the reduction. If one of the promises completed exceptionally, a Promise with an exception will be returned.
      • reduce

        public static <T,​A,​R> Promise<R> reduce​(A accumulator,
                                                            @NotNull
                                                            @NotNull BiConsumer<A,​T> consumer,
                                                            @NotNull
                                                            @NotNull Function<A,​R> finisher,
                                                            int maxCalls,
                                                            @NotNull
                                                            @NotNull Iterator<Promise<T>> promises)
        Type Parameters:
        T - type of input elements for this operation
        A - mutable accumulation type of the operation
        R - result type of the reduction operation
        Parameters:
        accumulator - supplier of the result
        consumer - a BiConsumer which folds a result of each of the completed promises into accumulator
        finisher - a Function which performs the final transformation from the intermediate accumulations
        maxCalls - max amount of concurrently running Promises
        promises - Iterable of Promises
        Returns:
        a Promise which wraps the accumulated result of the reduction. If one of the promises completed exceptionally, a Promise with an exception will be returned.
        See Also:
        reduce(Collector, int, Iterator)
      • coalesce

        @Contract(pure=true)
        @NotNull
        public static <T,​A,​R> @NotNull Function<T,​Promise<R>> coalesce​(@NotNull
                                                                                         @NotNull Supplier<A> argumentAccumulatorSupplier,
                                                                                         @NotNull
                                                                                         @NotNull BiConsumer<A,​T> argumentAccumulatorFn,
                                                                                         @NotNull
                                                                                         @NotNull Function<A,​Promise<R>> fn)