@@ -117,43 +117,16 @@ public async override IAsyncEnumerable<TPackageInfo> RunAsync<TPackageInfo>(IPip
117
117
118
118
_connectionTask = GetConnectionTask ( readTaskCompletionSource . Task , _cts . Token ) ;
119
119
120
- var packagePipeEnumerator = ReadPipeAsync < TPackageInfo > ( InputReader , _cts . Token ) . GetAsyncEnumerator ( _cts . Token ) ;
121
-
122
- Exception exception = null ;
123
-
124
- while ( true )
120
+ try
125
121
{
126
- var read = false ;
127
-
128
- try
129
- {
130
- read = await packagePipeEnumerator . MoveNextAsync ( ) . ConfigureAwait ( false ) ;
131
- }
132
- catch ( OperationCanceledException )
133
- {
134
- break ;
135
- }
136
- catch ( Exception e )
137
- {
138
- exception = e ;
139
- OnError ( "Unhandled exception in the method PipeConnection.Run." , e ) ;
140
- break ;
141
- }
142
-
143
- if ( read )
122
+ await foreach ( var packageInfo in ReadPipeAsync < TPackageInfo > ( InputReader , _cts . Token ) )
144
123
{
145
- yield return packagePipeEnumerator . Current ;
146
- continue ;
124
+ yield return packageInfo ;
147
125
}
148
-
149
- break ;
150
126
}
151
-
152
- readTaskCompletionSource . TrySetResult ( ) ;
153
-
154
- if ( exception != null )
127
+ finally
155
128
{
156
- throw exception ;
129
+ readTaskCompletionSource . TrySetResult ( ) ;
157
130
}
158
131
159
132
yield break ;
@@ -391,8 +364,6 @@ protected async IAsyncEnumerable<TPackageInfo> ReadPipeAsync<TPackageInfo>(PipeR
391
364
{
392
365
var pipelineFilter = _pipelineFilter as IPipelineFilter < TPackageInfo > ;
393
366
394
- Exception exception = null ;
395
-
396
367
while ( ! cancellationToken . IsCancellationRequested )
397
368
{
398
369
ReadResult result ;
@@ -431,7 +402,6 @@ protected async IAsyncEnumerable<TPackageInfo> ReadPipeAsync<TPackageInfo>(PipeR
431
402
432
403
if ( bufferFilterResult . Exception != null )
433
404
{
434
- exception = bufferFilterResult . Exception ;
435
405
OnError ( "Protocol error" , bufferFilterResult . Exception ) ;
436
406
CloseReason = Connection . CloseReason . ProtocolError ;
437
407
Close ( ) ;
@@ -460,12 +430,6 @@ protected async IAsyncEnumerable<TPackageInfo> ReadPipeAsync<TPackageInfo>(PipeR
460
430
}
461
431
462
432
await CompleteReaderAsync ( reader , _isDetaching ) . ConfigureAwait ( false ) ;
463
-
464
- if ( exception != null )
465
- {
466
- throw exception ;
467
- }
468
-
469
433
yield break ;
470
434
}
471
435
0 commit comments