-
Notifications
You must be signed in to change notification settings - Fork 226
Add nexus-cancelation sample #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| defer wg.Done() | ||
| // Use the cancelable callCtx for executing the operation. | ||
| fut := c.ExecuteOperation( | ||
| callCtx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| callCtx, | |
| ctx, |
| wg := workflow.NewWaitGroup(ctx) | ||
| for i, lang := range languages { | ||
| wg.Add(1) | ||
| workflow.Go(ctx, func(ctx workflow.Context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| workflow.Go(ctx, func(ctx workflow.Context) { | |
| workflow.Go(callCtx, func(ctx workflow.Context) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
|
I'm going to add a comment to note that the operation must be async in order to be cancelable and merge. |
|
I noticed I haven't added the sample to the README list, I'll add it in the next PR. |
See also temporalio/samples-java#718