Package com.helixframework.time
Class Timeout
java.lang.Object
com.helixframework.time.Timeout
Wrapper function that adds a timeout to the enclosed logic.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunction to execute in the event of a timeout.static interfaceFunction that adds a timeout to the call. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Texecute(Timeout.TimeoutFunction<T> fn, Timeout.FallbackFunction<T> fallbackFn, Duration timeout) Executes the wrapped function with a timeout and fallback.static <T> Texecute(Timeout.TimeoutFunction<T> fn, Duration timeout) Executes the wrapped function with a timeout.
-
Method Details
-
execute
public static <T> T execute(Timeout.TimeoutFunction<T> fn, Duration timeout) throws ExecutionException, InterruptedException, TimeoutException Executes the wrapped function with a timeout.- Type Parameters:
T- return type of the wrapped function- Parameters:
fn- wrapped function to executetimeout- function timeout- Returns:
- result of the wrapped function
- Throws:
ExecutionException- if an exception occurs in the wrapped functionInterruptedException- if the wrapped function is interruptedTimeoutException- if the timeout is exceededIllegalArgumentException- if a negative timeout is set
-
execute
public static <T> T execute(Timeout.TimeoutFunction<T> fn, Timeout.FallbackFunction<T> fallbackFn, Duration timeout) throws ExecutionException, InterruptedException Executes the wrapped function with a timeout and fallback. In the event of a timeout, the fallback function is executed.- Type Parameters:
T- return type of the wrapped function- Parameters:
fn- wrapped function to executefallbackFn- function to execute in the event of a timeouttimeout- function timeout- Returns:
- result of the wrapped function
- Throws:
ExecutionException- if an exception occurs in the wrapped functionInterruptedException- if the wrapped function is interruptedIllegalArgumentException- if a negative timeout is set
-