@@ -537,10 +537,38 @@ public static WorkflowInfo getWorkflowInfo() {
537
537
return WorkflowInternal .getWorkflowInfo ();
538
538
}
539
539
540
- public static <R > CancellationScope newCancellationScope (Runnable runnable ) {
540
+ /**
541
+ * Wraps the Runnable method argument in a {@link CancellationScope}. The {@link
542
+ * CancellationScope#run()} calls {@link Runnable#run()} on the wrapped Runnable. The returned
543
+ * CancellationScope can be used to cancel the wrapped code. The cancellation semantic depends on
544
+ * the operation the code is blocked on. For example activity or child workflow is first cancelled
545
+ * then throws a {@link CancellationException}. The same applies for {@link Workflow#sleep(long)}
546
+ * operation. When an activity or a child workflow is invoked asynchronously then they get
547
+ * cancelled and a {@link Promise} that contains their result will throw CancellationException
548
+ * when {@link Promise#get()} is called.
549
+ *
550
+ * <p>The new cancellation scope is linked to the parent one (available as {@link
551
+ * CancellationScope#current()}. If the parent one is cancelled then all the children scopes are
552
+ * cancelled automatically. The main workflow function (annotated with @{@link WorkflowMethod} is
553
+ * wrapped within a root cancellation scope which gets cancelled when a workflow is cancelled
554
+ * through the Cadence CancelWorkflowExecution API. To perform cleanup operations that require
555
+ * blocking after the current scope is cancelled use a scope created through {@link
556
+ * #newDetachedCancellationScope(Runnable)}.
557
+ *
558
+ * @param runnable parameter to wrap in a cancellation scope.
559
+ * @return wrapped parameter.
560
+ */
561
+ public static CancellationScope newCancellationScope (Runnable runnable ) {
541
562
return WorkflowInternal .newCancellationScope (false , runnable );
542
563
}
543
564
565
+ /**
566
+ * Creates a CancellationScope that is not linked to a parent scope.
567
+ *
568
+ * @param runnable parameter to wrap in a cancellation scope.
569
+ * @return wrapped parameter.
570
+ * @see #newCancellationScope(Runnable)
571
+ */
544
572
public static CancellationScope newDetachedCancellationScope (Runnable runnable ) {
545
573
return WorkflowInternal .newCancellationScope (true , runnable );
546
574
}
0 commit comments