Class CancellationSource

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

public final class CancellationSource extends Object
Creates a Cancellation and is the only thing that can fire it.

Java has no standard cancellation type, so the SDK supplies one. Hand the getCancellation() to a transport and keep the source; a transport that could cancel would be able to cancel the caller's own operation.

  • Method Details

    • create

      public static CancellationSource create()
      Create a new, uncancelled source.
      Returns:
      the new source
    • getCancellation

      public Cancellation getCancellation()
      Extract the observer side, safe to hand to a transport.
      Returns:
      the cancellation this source fires
    • cancel

      public void cancel()
      Fire the cancellation.

      Idempotent: a second call is a no-op, as is cancelling after the exchange has finished. Cancellation.isCancelled() returns true before any observer runs, observers run synchronously on this thread, and one that throws neither stops the others nor propagates here.