Cancel of a CancellationScope not working as expected

In your cancellation scope you can wait for the child workflow to start, for example (I also added exceptionally clause there to show you that you can catch the child workflow cancellation exception there as well):

CancellationScope getChildWorkflowCancelScope() {
      return Workflow.newCancellationScope(
          () -> {
            result =
                Async.function(childworkflowStub::ChildGreeting, 1)
                    .exceptionally(
                        e -> {
                          // exception here is going to be ChildWorkflowFailure
                          // with its cause being CanceledFailure as per your cancellation request     
                        });
            Promise<WorkflowExecution> childExecution =
                Workflow.getWorkflowExecution(childworkflowStub);
            // This call to .get will wait for child workflow to start execution
            childExecution.get();
          });
    }

If I read the issue correctly, this should help.

2 Likes