Add nexus-cancelation sample#393
Conversation
| defer wg.Done() | ||
| // Use the cancelable callCtx for executing the operation. | ||
| fut := c.ExecuteOperation( | ||
| callCtx, |
There was a problem hiding this comment.
| 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.
| workflow.Go(ctx, func(ctx workflow.Context) { | |
| workflow.Go(callCtx, func(ctx workflow.Context) { |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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