Class CancellationState

java.lang.Object
com.hedera.hashgraph.sdk.CancellationState

final class CancellationState extends Object
The state a CancellationSource and the Cancellation it hands out share.

Splitting the observer from the source is the point: a Cancellation is handed to third-party transports, code the SDK did not write, and if cancel() lived on it a transport could cancel the caller's own operation.

  • Constructor Details

    • CancellationState

      CancellationState()
  • Method Details

    • isCancelled

      boolean isCancelled()
    • cancel

      void cancel()
      Fire the cancellation. Idempotent; a second call is a no-op.

      isCancelled() returns true before any callback runs. Callbacks run synchronously on the calling thread, and one that throws neither prevents the others from running nor propagates to the caller.

    • onCancel

      CancellationRegistration onCancel(Runnable callback)
      Register an observer, running it immediately if the cancellation has already fired.
    • remove

      void remove(Runnable callback)