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

feat: RPC: add useAbortSignal option #731

Merged
merged 2 commits into from
Dec 14, 2022

Conversation

paralin
Copy link
Collaborator

@paralin paralin commented Dec 13, 2022

Adds a new option "useAbortSignal" which adds an optional AbortSignal parameter to RPC functions. AbortController and AbortSignal are built-ins in both Node.JS and all web browsers, which implement aborting long-lived processes.

For example:

const abortController = new AbortController()
const responsePromise = rpcClient.DoSomething(request, abortController.signal)
// abort the RPC call early
abortController.abort()

Fixes #730

Remove some unused variables triggering "unused variable" warnings.

Signed-off-by: Christian Stewart <christian@paral.in>
@paralin paralin requested review from stephenh, aikoven and fizx December 13, 2022 00:01
paralin added a commit to aperturerobotics/starpc that referenced this pull request Dec 13, 2022
Currently adds 1 patch for the following pending PR:

 - stephenh/ts-proto#730
 - stephenh/ts-proto#731

Signed-off-by: Christian Stewart <christian@paral.in>
paralin added a commit to aperturerobotics/starpc that referenced this pull request Dec 13, 2022
Currently adds 1 patch for the following pending PR:

 - stephenh/ts-proto#730
 - stephenh/ts-proto#731

Signed-off-by: Christian Stewart <christian@paral.in>
paralin added a commit to aperturerobotics/starpc that referenced this pull request Dec 13, 2022
Currently adds 1 patch for the following pending PR:

 - stephenh/ts-proto#730
 - stephenh/ts-proto#731

Signed-off-by: Christian Stewart <christian@paral.in>
paralin added a commit to aperturerobotics/starpc that referenced this pull request Dec 13, 2022
Currently adds 1 patch for the following pending PR:

 - stephenh/ts-proto#730
 - stephenh/ts-proto#731

Signed-off-by: Christian Stewart <christian@paral.in>
@paralin
Copy link
Collaborator Author

paralin commented Dec 13, 2022

@stephenh This should be good to go now. I wonder too about passing an AbortSignal on the server side.

Adds a new option "useAbortSignal" which adds an optional AbortSignal parameter
to RPC functions. AbortController and AbortSignal are built-ins in both Node.JS
and all web browsers, which implement aborting long-lived processes.

For example:

const abortController = new AbortController()
const responsePromise = rpcClient.DoSomething(request, abortController.signal)
// abort the RPC call early
abortController.abort()

Fixes stephenh#730

Signed-off-by: Christian Stewart <christian@paral.in>
paralin added a commit to aperturerobotics/starpc that referenced this pull request Dec 14, 2022
Currently adds 1 patch for the following pending PR:

 - stephenh/ts-proto#730
 - stephenh/ts-proto#731

Signed-off-by: Christian Stewart <christian@paral.in>
Copy link
Owner

@stephenh stephenh left a comment

Choose a reason for hiding this comment

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

Nice! Thanks @paralin !

I still haven't had a reason to use abort signals, so am not an expert, but this API seems really straightforward.

@stephenh stephenh merged commit 69313a7 into stephenh:main Dec 14, 2022
stephenh pushed a commit that referenced this pull request Dec 14, 2022
# [1.136.0](v1.135.3...v1.136.0) (2022-12-14)

### Features

* RPC: add useAbortSignal option ([#731](#731)) ([69313a7](69313a7)), closes [#730](#730)
@stephenh
Copy link
Owner

🎉 This PR is included in version 1.136.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@paralin paralin deleted the abort-controller branch December 14, 2022 22:46
paralin added a commit to aperturerobotics/starpc that referenced this pull request Dec 14, 2022
Currently adds 1 patch for the following pending PR:

 - stephenh/ts-proto#730
 - stephenh/ts-proto#731

Signed-off-by: Christian Stewart <christian@paral.in>
paralin added a commit to aperturerobotics/starpc that referenced this pull request Dec 14, 2022
Currently adds 1 patch for the following pending PR:

 - stephenh/ts-proto#730
 - stephenh/ts-proto#731

Signed-off-by: Christian Stewart <christian@paral.in>
paralin added a commit to aperturerobotics/starpc that referenced this pull request Dec 14, 2022
Currently adds 1 patch for the following pending PR:

 - stephenh/ts-proto#730
 - stephenh/ts-proto#731

Signed-off-by: Christian Stewart <christian@paral.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RPC: use AbortController and AbortSignal to cancel requests
2 participants