Package icyllis.modernui.core

# Class CancellationSignal

java.lang.Object
icyllis.modernui.core.CancellationSignal

public final class CancellationSignal extends Object
Provides the ability to cancel an operation in progress.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `CancellationSignal.OnCancelListener`
  Listens for cancellation.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CancellationSignal()`
  Creates a cancellation signal, initially not canceled.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `cancel()`
  Cancels the operation and signals the cancellation listener.
  `boolean`
  `isCanceled()`
  Returns true if the operation has been canceled.
  `void`
  `setOnCancelListener(CancellationSignal.OnCancelListener listener)`
  Sets the cancellation listener to be called when canceled.
  `void`
  `throwIfCanceled()`
  Throws `OperationCanceledException` if the operation has been canceled.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CancellationSignal

    public CancellationSignal()
    Creates a cancellation signal, initially not canceled.

- ## Method Details

  - ### isCanceled

    public boolean isCanceled()
    Returns true if the operation has been canceled.
    Returns:
      True if the operation has been canceled.

  - ### throwIfCanceled

    public void throwIfCanceled()
    Throws `OperationCanceledException` if the operation has been canceled.
    Throws:
      `OperationCanceledException` - if the operation has been canceled.

  - ### cancel

    public void cancel()
    Cancels the operation and signals the cancellation listener. If the operation has not yet started, then it will be canceled as soon as it does.

  - ### setOnCancelListener

    public void setOnCancelListener(@Nullable CancellationSignal.OnCancelListener listener)
    Sets the cancellation listener to be called when canceled.

    This method is intended to be used by the recipient of a cancellation signal such as a database or a content provider to handle cancellation requests while performing a long-running operation. This method is not intended to be used by applications themselves.

    If `cancel()` has already been called, then the provided listener is invoked immediately.

    This method is guaranteed that the listener will not be called after it has been removed.

    Parameters:
      `listener` - The cancellation listener, or null to remove the current listener.