Class Poll
java.lang.Object
codes.grow.packages.betterstack.core.Poll
Generic polling helper (
pollUntil): used by waitForLog, waitForTrace and
service waiters. Retryable SDK errors raised by an attempt are swallowed until the deadline;
other errors propagate.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TCallsattempteveryintervaluntil it returns a value ortimeoutpasses.static <T> CompletableFuture<T> untilAsync(String operation, Duration timeout, Duration interval, Supplier<CompletableFuture<Optional<T>>> attempt) Asynchronous variant ofuntil(java.lang.String, java.time.Duration, java.time.Duration, java.util.concurrent.Callable<java.util.Optional<T>>): no thread blocks between attempts.
-
Method Details
-
until
public static <T> T until(String operation, Duration timeout, Duration interval, Callable<Optional<T>> attempt) Callsattempteveryintervaluntil it returns a value ortimeoutpasses.- Type Parameters:
T- result type- Parameters:
operation- operation name for the timeout messagetimeout- overall deadlineinterval- pause between attemptsattempt- returns the value when the condition holds, empty otherwise- Returns:
- the first present value
- Throws:
TimeoutException- when the deadline passes (cause: last retryable error)CancelledException- when the thread is interrupted
-
untilAsync
public static <T> CompletableFuture<T> untilAsync(String operation, Duration timeout, Duration interval, Supplier<CompletableFuture<Optional<T>>> attempt) Asynchronous variant ofuntil(java.lang.String, java.time.Duration, java.time.Duration, java.util.concurrent.Callable<java.util.Optional<T>>): no thread blocks between attempts.- Type Parameters:
T- result type- Parameters:
operation- operation name for the timeout messagetimeout- overall deadlineinterval- pause between attemptsattempt- starts one attempt; completes with the value or empty- Returns:
- a future with the first present value, or failed with
TimeoutException
-