Skip to content

Commit 5e466b6

Browse files
committed
removal of cancellationtokensource
1 parent 0c89e9c commit 5e466b6

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/Serilog.Sinks.XUnit.Injectable/InjectableTestOutputSink.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ public sealed class InjectableTestOutputSink : IInjectableTestOutputSink
1919
private const string _defaultTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{Exception}";
2020

2121
private readonly MessageTemplateTextFormatter _fmt;
22-
private readonly Channel<LogEvent> _ch = Channel.CreateUnbounded<LogEvent>(
23-
new UnboundedChannelOptions { SingleReader = true, SingleWriter = false, AllowSynchronousContinuations = false });
22+
23+
private readonly Channel<LogEvent> _ch = Channel.CreateUnbounded<LogEvent>(new UnboundedChannelOptions
24+
{SingleReader = true, SingleWriter = false, AllowSynchronousContinuations = false});
25+
2426
private readonly Task _readerTask;
25-
private readonly CancellationTokenSource _cts = new();
2627

2728
private readonly ReusableStringWriter _sw = new();
2829

@@ -58,7 +59,7 @@ public void Emit(LogEvent logEvent)
5859

5960
private async Task ReadLoop()
6061
{
61-
await foreach (LogEvent evt in _ch.Reader.ReadAllAsync(_cts.Token).ConfigureAwait(false))
62+
await foreach (LogEvent evt in _ch.Reader.ReadAllAsync().ConfigureAwait(false))
6263
{
6364
ITestOutputHelper? helper = _helper; // volatile read
6465

@@ -107,17 +108,9 @@ public async ValueTask DisposeAsync()
107108
// 1) Tell the reader no more items are coming
108109
_ch.Writer.TryComplete();
109110

110-
try
111-
{
112-
// 2) Let the reader finish formatting & flushing
113-
await _readerTask.ConfigureAwait(false);
114-
}
115-
finally
116-
{
117-
// 3) Now it’s safe to cancel / dispose
118-
await _cts.CancelAsync().ConfigureAwait(false); // optional – keeps teardown symmetric
119-
_cts.Dispose();
120-
await _sw.DisposeAsync().ConfigureAwait(false);
121-
}
111+
// 2) Let the reader finish formatting & flushing
112+
await _readerTask.ConfigureAwait(false);
113+
114+
await _sw.DisposeAsync().ConfigureAwait(false);
122115
}
123116
}

0 commit comments

Comments
 (0)