Class UniRepeat<T>

java.lang.Object
io.smallrye.mutiny.groups.UniRepeat<T>
Type Parameters:
T - the type of item

public class UniRepeat<T> extends Object
Repeatedly subscribes to a given Uni to generate a Multi.
  • Constructor Details

    • UniRepeat

      public UniRepeat(Uni<T> upstream)
    • UniRepeat

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

    • withDelay

      @CheckReturnValue public UniRepeat<T> withDelay(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(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(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 whilst the predicate returns true.