Skip to content

Conversation

@Quinn-With-Two-Ns
Copy link
Contributor

Add Nexus cancellation sample

@Override
public NexusService.HelloOutput hello(NexusService.HelloInput input) {
// Sleep for a random duration to simulate some work
Workflow.sleep(Duration.ofSeconds(Workflow.newRandom().nextInt(5)));
Copy link
Member

Choose a reason for hiding this comment

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

Would encourage something a bit more deterministic here so that the same amount of cancellations happen every sample run (e.g. maybe pretend that EN is always slower or something)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, can do that

Copy link
Member

Choose a reason for hiding this comment

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

Let me know what you end up with and I'll update the Go sample. I kinda like that this isn't deterministic and you may get surprising results.

Comment on lines 83 to 86
// If the operation was cancelled, we can ignore the failure
if (e.getCause() instanceof CanceledFailure) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

Wonder if we should log or otherwise make clear to a user that the cancel occurred. User may not need it in their workflow, but for the sample, it's hard to know that anything even got canceled without going to the UI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

@Quinn-With-Two-Ns Quinn-With-Two-Ns merged commit c6a092e into temporalio:main Feb 27, 2025
5 checks passed
bergundy added a commit to temporalio/samples-go that referenced this pull request Feb 28, 2025
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.

3 participants