예제 #1
0
        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();
        }
예제 #2
0
 protected override ValueTask <ReadResult> ReadAtLeastAsyncCore(int minimumSize, CancellationToken cancellationToken)
 {
     _socketConnection.EnsureStarted();
     return(_reader.ReadAtLeastAsync(minimumSize, cancellationToken));
 }