Skip to content

Commit 2cc5431

Browse files
author
Ben de Bruyn
committed
#375 Cleanup code
1 parent 8876a33 commit 2cc5431

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/Docker.DotNet/Endpoints/StreamUtil.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)