Class UniRepeat<T>

  • Type Parameters:
    T - the type of item

    public class UniRepeat<T>
    extends java.lang.Object
    Repeatedly subscribes to a given Uni to generate a Multi.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Multi<T> atMost​(long times)
      Generates a stream, containing the items from the upstream Uni, resubscribed at most times times.
      Multi<T> indefinitely()
      Generates an unbounded stream, indefinitely resubscribing to the Uni.
      Multi<T> until​(java.util.function.Predicate<T> predicate)
      Generates a stream, containing the items from the upstream Uni, resubscribed until the given predicate returns true.
      Multi<T> whilst​(java.util.function.Predicate<T> predicate)
      Generates a stream, containing the items from the upstream Uni, resubscribed while the given predicate returns true.
      UniRepeat<T> withDelay​(java.time.Duration delay)
      Adds a fixed delay between the next repetition.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UniRepeat

        public UniRepeat​(Uni<T> upstream)
      • UniRepeat

        public UniRepeat​(Uni<T> upstream,
                         Uni<?> delay)
    • Method Detail

      • withDelay

        @CheckReturnValue
        public UniRepeat<T> withDelay​(java.time.Duration delay)
        Adds a fixed delay between the next repetition. Such a delay can be used when interacting with an API using rate limiting.
        Parameters:
        delay - the delay, must be not null, must be positive
        Returns:
        the UniRepeat configured with the delay.
      • indefinitely

        @CheckReturnValue
        public Multi<T> indefinitely()
        Generates an unbounded stream, indefinitely resubscribing to the Uni. Note that this enforces:
        • the number of requests coming from the subscriber
        • cancellation
        • failures, that are propagated downstream

        The produced Multi contains the items emitted by the upstream Uni. After every emission, another subscription is performed on the Uni, and the item is then propagated. If the Uni fires a failure, the failure is propagated. If the Uni emits `null` as item, it resubscribes.

        Returns:
        the Multi containing the items from the upstream Uni, resubscribed indefinitely.
      • atMost

        @CheckReturnValue
        public Multi<T> atMost​(long times)
        Generates a stream, containing the items from the upstream Uni, resubscribed at most times times.

        Note that this enforces:

        • the number of requests coming from the subscriber
        • cancellation
        • failures, that are propagated downstream

        The produced Multi contains the items emitted by the upstream Uni. After every emission, another subscription is performed on the Uni, and the item is then propagated. If the Uni fires a failure, the failure is propagated. If the Uni emits `null` as item, it resubscribes.

        This method is named atMost because the repeating re-subscription can be stopped if the subscriber cancels its subscription to the produced Multi.

        Parameters:
        times - the number of re-subscription, must be strictly positive, 1 is equivalent to Uni.toMulti()
        Returns:
        the Multi containing the items from the upstream Uni, resubscribed at most times times.
      • until

        @CheckReturnValue
        public Multi<T> until​(java.util.function.Predicate<T> predicate)
        Generates a stream, containing the items from the upstream Uni, resubscribed until the given predicate returns true. The predicate is called on the item produced by the Uni. If it passes, the item is not propagated downstream and the repetition is stopped.

        Unlike whilst(Predicate), the checked item is only propagated downstream if it did not pass the predicate. For example, if you use an API returning "null" or an empty set once you reach the end, you can stop the repetition when this case is detected.

        The predicate is not called on null item. If you want to intercept this case, use a sentinel item.

        If the Uni propagates a failure, the failure is propagated and the repetition stopped.

        Parameters:
        predicate - the predicate, must not be null
        Returns:
        the Multi containing the items from the upstream Uni, resubscribed until the predicate returns true.
      • whilst

        @CheckReturnValue
        public Multi<T> whilst​(java.util.function.Predicate<T> predicate)
        Generates a stream, containing the items from the upstream Uni, resubscribed while the given predicate returns true.

        The uni is subscribed at least once. The item is checked. Regardless the result of the predicate, the item is propagated downstream. If the test passed, the repetition continues, otherwise the repetition is stopped.

        Unlike until(Predicate), the checked item is propagated downstream regardless if it passed the predicate. For example, if you use a Rest API specifying the "next page", you can stop the repetition when the "next page" is absent, while still propagating downstream the current page.

        The predicate is not called on null item. If you want to intercept this case, use a sentinel item.

        If the Uni propagates a failure, the failure is propagated and the repetition stopped.

        Parameters:
        predicate - the predicate, must not be null
        Returns:
        the Multi containing the items from the upstream Uni, resubscribed until the predicate returns true.