Skip to content

Commit 102f4bd

Browse files
authored
Simply SignalR Client IAsyncEnumerable usage (#56561)
Today we create a separate "cancelable" async enumerable so we can "link" the passed in CancellationTokenSource with the CancellationToken passed into GetAsyncEnumerator. We don't need to do this in this scenario because we are the ones enumerating over the object, and we aren't passing in a CancellationToken during the enumeration. Instead, we can simply enumerate over the supplied IAsyncEnumerable and call WithCancellation, passing in the supplied CancellationTokenSource.
1 parent 59d4050 commit 102f4bd

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,7 @@ private Task SendIAsyncEnumerableStreamItems<T>(ConnectionState connectionState,
899899
{
900900
async Task ReadAsyncEnumerableStream()
901901
{
902-
var streamValues = AsyncEnumerableAdapters.MakeCancelableTypedAsyncEnumerable(stream, tokenSource);
903-
904-
await foreach (var streamValue in streamValues.ConfigureAwait(false))
902+
await foreach (var streamValue in stream.WithCancellation(tokenSource.Token).ConfigureAwait(false))
905903
{
906904
await SendWithLock(connectionState, new StreamItemMessage(streamId, streamValue), tokenSource.Token).ConfigureAwait(false);
907905
Log.SendingStreamItem(_logger, streamId);

0 commit comments

Comments
 (0)