Class DeadlineGuard

java.lang.Object
io.helidon.common.task.DeadlineGuard
All Implemented Interfaces:
AutoCloseable

public final class DeadlineGuard extends Object implements AutoCloseable
Guard for a scoped operation with a deadline.

The guard schedules an action to run when the configured timeout expires. Closing the guard cancels the scheduled action if it has not already run.

  • Method Details

    • create

      public static DeadlineGuard create(Duration timeout, Runnable timeoutAction)
      Creates a new guard and starts its timeout immediately.

      A zero or negative timeout creates a guard that never expires.

      Parameters:
      timeout - timeout to wait before invoking the timeout action
      timeoutAction - action to invoke when the timeout expires
      Returns:
      active deadline guard
    • timedOut

      public boolean timedOut()
      Whether this guard's timeout elapsed and its timeout action was invoked.
      Returns:
      whether the guard timed out
    • timeoutActionFailure

      public Optional<Throwable> timeoutActionFailure()
      Failure thrown by the timeout action, if any.
      Returns:
      timeout action failure
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable