Class UniRepeat<T>
- java.lang.Object
-
- io.smallrye.mutiny.groups.UniRepeat<T>
-
- Type Parameters:
T
- the type of item
public class UniRepeat<T> extends java.lang.Object
-
-
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 upstreamUni
, resubscribed at mosttimes
times.Multi<T>
indefinitely()
Generates an unbounded stream, indefinitely resubscribing to theUni
.Multi<T>
until(java.util.function.Predicate<T> predicate)
Generates a stream, containing the items from the upstreamUni
, resubscribed until the given predicate returnstrue
.Multi<T>
whilst(java.util.function.Predicate<T> predicate)
Generates a stream, containing the items from the upstreamUni
, resubscribed while the given predicate returnstrue
.UniRepeat<T>
withDelay(java.time.Duration delay)
Adds a fixed delay between the next repetition.
-
-
-
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 notnull
, must be positive- Returns:
- the
UniRepeat
configured with the delay.
-
indefinitely
@CheckReturnValue public Multi<T> indefinitely()
Generates an unbounded stream, indefinitely resubscribing to theUni
. 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 upstreamUni
. After every emission, another subscription is performed on theUni
, and the item is then propagated. If theUni
fires a failure, the failure is propagated. If theUni
emits `null` as item, it resubscribes.
-
atMost
@CheckReturnValue public Multi<T> atMost(long times)
Generates a stream, containing the items from the upstreamUni
, resubscribed at mosttimes
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 upstreamUni
. After every emission, another subscription is performed on theUni
, and the item is then propagated. If theUni
fires a failure, the failure is propagated. If theUni
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 producedMulti
.- Parameters:
times
- the number of re-subscription, must be strictly positive, 1 is equivalent toUni.toMulti()
- Returns:
- the
Multi
containing the items from the upstreamUni
, resubscribed at mosttimes
times.
-
until
@CheckReturnValue public Multi<T> until(java.util.function.Predicate<T> predicate)
Generates a stream, containing the items from the upstreamUni
, resubscribed until the given predicate returnstrue
. The predicate is called on the item produced by theUni
. 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.
-
whilst
@CheckReturnValue public Multi<T> whilst(java.util.function.Predicate<T> predicate)
Generates a stream, containing the items from the upstreamUni
, resubscribed while the given predicate returnstrue
.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.
-
-