How to cascade workflow cancellation to related workflows in golang

I’ve been reading @maxim 's articles 1 & 2 on how to implement a cleanup() method when a cancellation occurs but I’m stuck. The documentation (too many links for a new user) seems to only talk about passing that cancellation to the activity which is different from what I want.

The pseudo code what I’m trying to do is something like this:

func MyWorkflow(ctx workflow.Context, request MyWorkflowRequest) error {
	// Register signal channels
	// ...

	// Related workflows
	relatedWorkflowIds := []string{
		//...
	}

	// Handle cancellation from this point forward, anywhere in the workflow
	go func(ctx workflow.Context) {
		for {
			select {
			case <-ctx.Done():
				// Cascade cancellation to related workflows
				fmt.Println("Context cancelled:", ctx.Err())
				newCtx, _ := workflow.NewDisconnectedContext(ctx)
				client, err := clients.NewClient() 
				for _, workflowId := range relatedWorkflowIds {
					err = client.CancelWorkflow(newCtx.Background(), workflowId, "")
					if err != nil {
						log.Fatalln("Unable to cancel Workflow Execution", err)
					}
				}
				return
			}
		}
	}(ctx)

	// Do some activities

	// sleep for set period

	// Do some more activities
	return nil
}

This doesn’t seem to work because of something @maxim said about the context is not the same as the go-lang’s standard context I think.

You cannot use the client in the workflow code as it performs direct IO. All calls through the client must be done from activities.

Are you trying to cancel a child workflow or some unrelated workflow?

it’s a different workflow (not a child). Although, I’m considering switching to child workflows if this is not achievable. I would be OK with calling an activity that triggers the cascade. My issue with the documentation is that it talks about canceling an activity that is already running.

For unrelated workflow use RequestCancelExternalWorkflow.