Skip to content

Conversation

@bergundy
Copy link
Member

defer wg.Done()
// Use the cancelable callCtx for executing the operation.
fut := c.ExecuteOperation(
callCtx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
callCtx,
ctx,

wg := workflow.NewWaitGroup(ctx)
for i, lang := range languages {
wg.Add(1)
workflow.Go(ctx, func(ctx workflow.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
workflow.Go(ctx, func(ctx workflow.Context) {
workflow.Go(callCtx, func(ctx workflow.Context) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good, call, missed this during refactoring, I'm ignoring this sub-context in the call. I wonder if this matters in practice, but agree this is better in a sample.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it can, in this case probably not but it is best practice. We always recommend in the Go SDK to use the context of the function you are in.

err: err,
}
// The first operation to win the race cancels the others.
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit different then the Java sample, there we waited for everything to start before cancelling

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't matter though, since the server will wait for start for us.
You can do the same in Java.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the sample should be written assuming a generic async operation and not rely on specific behaviour of a workflow run

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server doesn't know this is a workflow run operation, just that it's async (as indicated by the token returned from the handler).

@bergundy
Copy link
Member Author

I'm going to add a comment to note that the operation must be async in order to be cancelable and merge.

@bergundy
Copy link
Member Author

I noticed I haven't added the sample to the README list, I'll add it in the next PR.

@bergundy bergundy merged commit 7cbb8b9 into temporalio:main Feb 28, 2025
3 checks passed
@bergundy bergundy deleted the nexus-cancelation branch February 28, 2025 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants