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

Cancellation token support for async methods #18

Open
alex-bortnik opened this issue Jun 9, 2022 · 5 comments
Open

Cancellation token support for async methods #18

alex-bortnik opened this issue Jun 9, 2022 · 5 comments

Comments

@alex-bortnik
Copy link

Hi,

we would like to add cancellation tokens support for async methods.
I prepared PR (see patch in attachment). It also includes update from obsolete WebRequest to HttpClient

(please rename from txt -> patch)

cancellation_token_support_for_async_methods.txt
.

@jkw-statsig
Copy link
Contributor

jkw-statsig commented Jun 9, 2022

Hi @alex-bortnik - we just closed an issue yesterday about this, and we provided an option for users to configure timeouts on these requests, which sounds like would be helpful to you. Can you take a look at #12 and see if that works first?

I see that you've added cancellation tokens to functions like CheckGate - these functions are async but should actually return instantaneously because it just performs a local evaluation, so I'm not sure if cancellation token is really needed here.

@alex-bortnik
Copy link
Author

alex-bortnik commented Jun 10, 2022

Hi @jkw-statsig - yes, I saw that, my PR is based on #12 implementation. This PR allows to provide either timeout or cancellation token.

Override with optional cancellation token is added only to the public methods which are calling RequestDispatcher.Fetch (where actual http request is being sent).

Implementation of RequestDispatcher.Fetch is switched from WebRequest to HttpClient which has better async support. Also WebRequest is already declared obsolete: https://docs.microsoft.com/en-us/dotnet/core/compatibility/networking/6.0/webrequest-deprecated

@alex-bortnik
Copy link
Author

Also, the common practice in .NET/C# is to pass cancellation token downstream from upper layer.
It is not possible to get remaining timeout value from cancellation token downstream.
Plus there could be other reasons for cancellation apart from timeout.

@jkw-statsig
Copy link
Contributor

Got it, thanks for the context. We'll take a look into your patch

@mitchell-arthur-wealth
Copy link

@jkw-statsig any update on this?

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

No branches or pull requests

3 participants