@@ -14,15 +14,12 @@ internal static async Task MonitorStreamAsync(Task<Stream> streamTask, DockerCli
1414 using ( var stream = await streamTask )
1515 {
1616 // ReadLineAsync must be cancelled by closing the whole stream.
17- // using (cancel.Register(() => stream.Dispose( )))
17+ using ( var reader = new StreamReader ( stream , new UTF8Encoding ( false ) ) )
1818 {
19- using ( var reader = new StreamReader ( stream , new UTF8Encoding ( false ) ) )
19+ string line ;
20+ while ( ( line = await reader . ReadLineAsync ( ) ) != null && ! cancel . IsCancellationRequested )
2021 {
21- string line ;
22- while ( ( line = await reader . ReadLineAsync ( ) ) != null && ! cancel . IsCancellationRequested )
23- {
24- progress . Report ( line ) ;
25- }
22+ progress . Report ( line ) ;
2623 }
2724 }
2825 }
@@ -33,27 +30,24 @@ internal static async Task MonitorStreamForMessagesAsync<T>(Task<Stream> streamT
3330 using ( var stream = await streamTask )
3431 {
3532 // ReadLineAsync must be cancelled by closing the whole stream.
36- // using (cancel.Register(() => stream.Dispose( )))
33+ using ( var reader = new StreamReader ( stream , new UTF8Encoding ( false ) ) )
3734 {
38- using ( var reader = new StreamReader ( stream , new UTF8Encoding ( false ) ) )
35+ string line ;
36+ try
3937 {
40- string line ;
41- try
38+ while ( ( line = await reader . ReadLineAsync ( ) ) != null && ! cancel . IsCancellationRequested )
4239 {
43- while ( ( line = await reader . ReadLineAsync ( ) ) != null && ! cancel . IsCancellationRequested )
44- {
45- var prog = client . JsonSerializer . DeserializeObject < T > ( line ) ;
46- if ( prog == null ) continue ;
40+ var prog = client . JsonSerializer . DeserializeObject < T > ( line ) ;
41+ if ( prog == null ) continue ;
4742
48- progress . Report ( prog ) ;
49- }
50- }
51- catch ( ObjectDisposedException )
52- {
53- // The subsequent call to reader.ReadLineAsync() after cancellation
54- // will fail because we disposed the stream. Just ignore here.
43+ progress . Report ( prog ) ;
5544 }
5645 }
46+ catch ( ObjectDisposedException )
47+ {
48+ // The subsequent call to reader.ReadLineAsync() after cancellation
49+ // will fail because we disposed the stream. Just ignore here.
50+ }
5751 }
5852 }
5953 }
0 commit comments