Skip to content

Commit

Permalink
Set task as Canceled based on token
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcholette committed Feb 13, 2024
1 parent 8ac5cf7 commit 68680df
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/JsonRpc/ResponseRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
var tcs = new TaskCompletionSource<JToken>();
_router.Requests.TryAdd(nextId, ( _method, tcs ));

cancellationToken.ThrowIfCancellationRequested();

try
{
cancellationToken.ThrowIfCancellationRequested();

_router.OutputHandler.Value.Send(
new OutgoingRequest
{
Expand All @@ -117,6 +117,13 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
() =>
{
if (tcs.Task.IsCompleted) return;

if (cancellationToken.IsCancellationRequested)
{
tcs.SetCanceled();
return;
}

_router.CancelRequest(new CancelParams { Id = nextId });
}
);
Expand Down

0 comments on commit 68680df

Please sign in to comment.