Class CancelSource<E extends RuntimeException>

java.lang.Object
io.temporal.internal.concurrent.structured.CancelSource<E>
Type Parameters:
E - the exception surfaced by the token when cancellation is requested

public final class CancelSource<E extends RuntimeException> extends Object
The write side of cancellation. Whoever holds the CancelSource can request cancellation while everyone else observes using token().

Sources can be linked: a source created via linkedTo(java.util.function.Supplier<E>, io.temporal.common.CancellationToken<? extends E>...) is cancelled automatically when any of its parent tokens is cancelled, without giving the child the power to cancel the parent.

  • Constructor Details

    • CancelSource

      public CancelSource(Supplier<E> defaultException)
  • Method Details

    • token

      public CancellationToken<E> token()
      The read-only token to hand to code that observes cancellation.
    • isCancelled

      public boolean isCancelled()
    • cancel

      public void cancel()
      Requests cancellation with a freshly created exception.
    • cancel

      public void cancel(E exception)
      Requests cancellation, surfacing exception from the token. Idempotent.
    • linkedTo

      @SafeVarargs public static <E extends RuntimeException> CancelSource<E> linkedTo(Supplier<E> defaultException, CancellationToken<? extends E>... parents)
      Creates a source whose token is cancelled (via cancel()) whenever any parent token is cancelled.