Interface CancellationToken


@API(status=EXPERIMENTAL, since="6.0") public sealed interface CancellationToken
Token that should be checked to determine whether an operation was requested to be cancelled.

For example, this is used by the Launcher and TestEngine implementations to determine whether the current test execution should be cancelled.

This interface is not intended to be implemented by clients.

Since:
6.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Request cancellation.
    Create a new, uncancelled cancellation token.
    Get a new cancellation token that cannot be cancelled.
    boolean
    Returns whether cancellation has been requested.
  • Method Details

    • create

      static CancellationToken create()
      Create a new, uncancelled cancellation token.
    • disabled

      static CancellationToken disabled()
      Get a new cancellation token that cannot be cancelled.

      This is only useful for cases when a cancellation token is required but is not supported or irrelevant, for example, in tests.

    • isCancellationRequested

      boolean isCancellationRequested()
      Returns whether cancellation has been requested.

      Once this method returns true, it will never return false in a subsequent call.

      Returns:
      whether cancellation has been requested
    • cancel

      void cancel()
      Request cancellation.

      This will call subsequent calls to isCancellationRequested() to return true.