Skip to content

Commit 4afb582

Browse files
author
David García Vives
committed
Applied solution from dotnet#394 by @Duracell1989 to cancel MonitorLogs Ttask
1 parent 5931cbe commit 4afb582

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Docker.DotNet/Endpoints/StreamUtil.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
using Newtonsoft.Json;
21
using System;
32
using System.IO;
43
using System.Net.Http;
54
using System.Text;
65
using System.Threading;
76
using System.Threading.Tasks;
7+
using Newtonsoft.Json;
88

99
namespace Docker.DotNet.Models
1010
{
1111
internal static class StreamUtil
1212
{
1313
private static readonly Newtonsoft.Json.JsonSerializer _serializer = new Newtonsoft.Json.JsonSerializer();
1414

15-
internal static async Task MonitorStreamAsync<T>(Task<Stream> streamTask, DockerClient client, CancellationToken cancel, IProgress<T> progress)
15+
internal static async Task MonitorStreamAsync(Task<Stream> streamTask, DockerClient client, CancellationToken cancel, IProgress<string> progress)
1616
{
17-
await MonitorStreamForMessagesAsync<T>(streamTask, client, cancel, progress);
17+
18+
using (var stream = await streamTask)
19+
{
20+
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
21+
{
22+
string line;
23+
while ((line = await reader.ReadLineAsync()) != null && !cancel.IsCancellationRequested)
24+
{
25+
progress.Report(line);
26+
}
27+
}
28+
}
1829
}
1930

2031
internal static async Task MonitorStreamForMessagesAsync<T>(Task<Stream> streamTask, DockerClient client, CancellationToken cancel, IProgress<T> progress)

0 commit comments

Comments
 (0)