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

CancellationToken not responsive #140

Closed
groege opened this issue Nov 13, 2019 · 1 comment
Closed

CancellationToken not responsive #140

groege opened this issue Nov 13, 2019 · 1 comment

Comments

@groege
Copy link

groege commented Nov 13, 2019

When cancelling SendQueryAsync with a CancellationToken, there will be no immediate TaskCancelledException thrown

I'm using this workaround right now:

        private static Task<GraphQLResponse> SendQueryAsyncX(this GraphQLHttpClient client, GraphQLRequest request, CancellationToken ct)
        {
            TaskCompletionSource<GraphQLResponse> tcs = new TaskCompletionSource<GraphQLResponse>();
            ct.Register(() => tcs.TrySetCanceled());

            client.SendQueryAsync(request, ct).ContinueWith(result =>
            {
                if (result.IsFaulted)
                {
                    tcs.TrySetException(result.Exception);
                }
                else if (result.IsCanceled)
                {
                    tcs.TrySetCanceled();
                }
                else
                {
                    tcs.TrySetResult(result.Result);
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
            return tcs.Task;
        }

When a CancellationToken is cancelled, the Task should complete without any time lag to allow responsiveness out of the box.

@rose-a
Copy link
Collaborator

rose-a commented Feb 6, 2020

which version of the library are you using?

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

2 participants