@@ -102,7 +102,6 @@ public static async ValueTask<List<T>> ReadBatchAsync<T>(this ChannelReader<T> r
102102 if ( results . Count == max )
103103 return results ;
104104
105- cancellationToken . ThrowIfCancellationRequested ( ) ;
106105 }
107106 while ( await reader . WaitToReadAsync ( cancellationToken ) . ConfigureAwait ( false ) ) ;
108107 }
@@ -134,8 +133,9 @@ public static async ValueTask<long> ReadUntilCancelledAsync<T>(this ChannelReade
134133 if ( deferredExecution )
135134 await Task . Yield ( ) ;
136135
137- long index = 0 ;
136+ long count = 0 ;
138137
138+ // Note: if the channel has complete with an OperationCanceledException, this will throw when waiting to read.
139139 if ( cancellationToken . CanBeCanceled )
140140 {
141141 do
@@ -144,7 +144,7 @@ public static async ValueTask<long> ReadUntilCancelledAsync<T>(this ChannelReade
144144 ! cancellationToken . IsCancellationRequested
145145 && reader . TryRead ( out T ? item ) )
146146 {
147- await receiver ( item , index ++ ) . ConfigureAwait ( false ) ;
147+ await receiver ( item , count ++ ) . ConfigureAwait ( false ) ;
148148 }
149149 }
150150 while (
@@ -157,13 +157,13 @@ public static async ValueTask<long> ReadUntilCancelledAsync<T>(this ChannelReade
157157 {
158158 while ( reader . TryRead ( out T ? item ) )
159159 {
160- await receiver ( item , index ++ ) . ConfigureAwait ( false ) ;
160+ await receiver ( item , count ++ ) . ConfigureAwait ( false ) ;
161161 }
162162 }
163- while ( await reader . WaitToReadOrCancelAsync ( cancellationToken ) . ConfigureAwait ( false ) ) ;
163+ while ( await reader . WaitToReadAsync ( cancellationToken ) . ConfigureAwait ( false ) ) ;
164164 }
165165
166- return index ;
166+ return count ;
167167 }
168168
169169 /// <summary>
@@ -250,7 +250,7 @@ public static ValueTask<long> ReadUntilCancelled<T>(this ChannelReader<T> reader
250250 ( e , i ) =>
251251 {
252252 receiver ( e , i ) ;
253- return new ValueTask ( ) ;
253+ return default ;
254254 } ,
255255 deferredExecution ) ;
256256
@@ -297,7 +297,7 @@ public static ValueTask<long> ReadUntilCancelled<T>(this ChannelReader<T> reader
297297 ( e , _ ) =>
298298 {
299299 receiver ( e ) ;
300- return new ValueTask ( ) ;
300+ return default ;
301301 } ,
302302 deferredExecution ) ;
303303
@@ -356,7 +356,7 @@ public static ValueTask ReadAllAsEnumerables<T>(this ChannelReader<T> reader,
356356 e =>
357357 {
358358 receiver ( e ) ;
359- return new ValueTask ( ) ;
359+ return default ;
360360 } ,
361361 deferredExecution ,
362362 cancellationToken ) ;
@@ -396,7 +396,7 @@ public static async ValueTask ReadAllAsEnumerablesAsync<T>(this ChannelReader<T>
396396 return ;
397397 }
398398
399- while ( await reader . WaitToReadOrCancelAsync ( cancellationToken ) . ConfigureAwait ( false ) )
399+ while ( await reader . WaitToReadAsync ( cancellationToken ) . ConfigureAwait ( false ) )
400400 {
401401 await receiver ( reader . ReadAvailable ( cancellationToken ) ) . ConfigureAwait ( false ) ;
402402 }
@@ -775,7 +775,7 @@ public static ValueTask<long> ReadAll<T>(this ChannelReader<T> reader,
775775 . ReadAllAsync ( ( e , i ) =>
776776 {
777777 receiver ( e , i ) ;
778- return new ValueTask ( ) ;
778+ return default ;
779779 } ,
780780 deferredExecution ,
781781 cancellationToken ) ;
@@ -894,7 +894,7 @@ public static ValueTask<long> ReadAll<T>(this ChannelReader<T> reader,
894894 ( e , _ ) =>
895895 {
896896 receiver ( e ) ;
897- return new ValueTask ( ) ;
897+ return default ;
898898 } ,
899899 deferredExecution ,
900900 cancellationToken ) ;
0 commit comments