Skip to content
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

chore(examples): Add cancellation example #1477

Merged
merged 3 commits into from
Aug 25, 2023

Conversation

tcohen01
Copy link
Contributor

Motivation

There are some valid usecases for being notified of request cancellation and executing clean up logic on client cancellation.
This can be easily done with server streaming and bidi streaming, but there doesn't seem to be a straightforward approach for unary RPCs.

Solution

Creating a new task for unary requests (like in server/bidi streaming requests), having the unary request' future await on this new task with a CancellationToken drop guard.

Under the assumption that request futures are dropped when client cancels the request, this will notify the task through the drop guard's drop logic

@tcohen01
Copy link
Contributor Author

Example is testable using hello world's client - simply let the server finish handling the request or stop the hello world client before the server finishes the request.

Also, not sure if the futures in this example should be fused before selecting on them - will add if so.

@LucioFranco LucioFranco added this pull request to the merge queue Aug 25, 2023
Merged via the queue into hyperium:master with commit 8cba85e Aug 25, 2023
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