-
Notifications
You must be signed in to change notification settings - Fork 136
Closed
Description
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.
Metadata
Metadata
Assignees
Labels
No labels