Class OnceConsumer<T>
- java.lang.Object
-
- io.github.resilience4j.core.functions.OnceConsumer<T>
-
- Type Parameters:
T
- the type of the input which is passed to the consumer and executed once.
public final class OnceConsumer<T> extends java.lang.Object
Apply a computation only once.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyOnce(java.util.function.Consumer<T> consumer)
Apply a computation on subject only once.static <T> OnceConsumer<T>
of(T t)
Create a do once consumer.
-
-
-
Method Detail
-
of
public static <T> OnceConsumer<T> of(T t)
Create a do once consumer.- Type Parameters:
T
- type of input on which operation is applied.- Parameters:
t
- input which is passed to operation- Returns:
-
applyOnce
public void applyOnce(java.util.function.Consumer<T> consumer)
Apply a computation on subject only once.List<String> lst = new ArrayList<>(); OnceConsumer<List<String>> once = OnceConsumer.of(lst); once.applyOnce((l) -> l.add("Hello World")); once.applyOnce((l) -> l.add("Hello World")); assertThat(lst).hasSize(1).contains("Hello World");
- Parameters:
consumer
- computation run once with input t
-
-