public async Task ReadCanBeCanceledViaCancelPendingReadWhenReadAtLeastAsync(bool useZeroByteReads) { var stream = new CancelledReadsStream(); PipeReader reader = PipeReader.Create(stream, new StreamPipeReaderOptions(useZeroByteReads: useZeroByteReads)); ValueTask <ReadResult> task = reader.ReadAtLeastAsync(1); reader.CancelPendingRead(); stream.WaitForReadTask.TrySetResult(null); ReadResult readResult = await task; Assert.True(readResult.IsCanceled); reader.Complete(); }
protected override ValueTask <ReadResult> ReadAtLeastAsyncCore(int minimumSize, CancellationToken cancellationToken) { _socketConnection.EnsureStarted(); return(_reader.ReadAtLeastAsync(minimumSize, cancellationToken)); }