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