Skip to content

Commit 68680df

Browse files
Set task as Canceled based on token
1 parent 8ac5cf7 commit 68680df

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/JsonRpc/ResponseRouter.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
101101
var tcs = new TaskCompletionSource<JToken>();
102102
_router.Requests.TryAdd(nextId, ( _method, tcs ));
103103

104-
cancellationToken.ThrowIfCancellationRequested();
105-
106104
try
107105
{
106+
cancellationToken.ThrowIfCancellationRequested();
107+
108108
_router.OutputHandler.Value.Send(
109109
new OutgoingRequest
110110
{
@@ -117,6 +117,13 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
117117
() =>
118118
{
119119
if (tcs.Task.IsCompleted) return;
120+
121+
if (cancellationToken.IsCancellationRequested)
122+
{
123+
tcs.SetCanceled();
124+
return;
125+
}
126+
120127
_router.CancelRequest(new CancelParams { Id = nextId });
121128
}
122129
);

0 commit comments

Comments
 (0)