Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ public override bool TryComplete(Exception? error)
// Complete a blocked reader if necessary
if (blockedReader is not null)
{
error = ChannelUtilities.CreateInvalidCompletionException(error);
blockedReader.TrySetException(error);
blockedReader.TrySetException(ChannelUtilities.CreateInvalidCompletionException(error));
}

// Complete a waiting reader if necessary. (We really shouldn't have both a blockedReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ public async Task MultipleReaders_CancelsPreviousReader()
Assert.Equal(42, await t2);
}

[Fact]
public async Task WaitToReadAsync_ReturnsFalse_WhenReadAsyncWasCanceledAndChannelCompleted()
{
Channel<int> c = CreateChannel();

using var cts = new CancellationTokenSource();
ValueTask<int> readTask = c.Reader.ReadAsync(cts.Token);
cts.Cancel();
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await readTask);

ValueTask<bool> waitTask = c.Reader.WaitToReadAsync(CancellationToken.None);

c.Writer.Complete();

Assert.False(await waitTask);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMultithreadingSupported))]
public void Stress_TryWrite_TryRead()
{
Expand Down
Loading