Interface CancellationToken


public interface CancellationToken
Cancellation token is an object that is issued by CancelHandle and can be used by an operation or a resource to observe a signal to terminate it.
  • Method Summary

    Modifier and Type
    Method
    Description
    Registers a callback to be executed when cancellation is requested.
    boolean
    Flag indicating whether cancellation was requested or not.
  • Method Details

    • isCancelled

      boolean isCancelled()
      Flag indicating whether cancellation was requested or not.

      This method will return true even if cancellation has not been completed yet.

      Returns:
      true when cancellation was requested.
    • addListener

      AutoCloseable addListener(Runnable callback)
      Registers a callback to be executed when cancellation is requested. If cancellation has already been requested, the callback is executed immediately.

      The returned handle can be used to stop listening for cancellation requests. It is important to close the handle when the callback is no longer needed to avoid memory leaks.

      Parameters:
      callback - Callback to execute when cancellation is requested.
      Returns:
      A handle which can be used to stop listening for cancellation requests.