Ejemplo n.º 1
0
        public void WaitToWriteAsync_Completed_SynchronousResult()
        {
            using (AnonymousPipeServerStream serverPipe = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                IWritableChannel <int> writer = Channel.WriteToStream <int>(serverPipe);
                AssertSynchronousTrue(writer.WaitToWriteAsync());

                writer.Complete();
                AssertSynchronousFalse(writer.WaitToWriteAsync());

                var cts = new CancellationTokenSource();
                cts.Cancel();
                AssertSynchronouslyCanceled(writer.WaitToWriteAsync(cts.Token), cts.Token);
            }
        }
Ejemplo n.º 2
0
        public void WriteToStream_Precancellation()
        {
            IWritableChannel <int> w = Channel.WriteToStream <int>(new MemoryStream());
            var cts = new CancellationTokenSource();

            cts.Cancel();
            AssertSynchronouslyCanceled(w.WaitToWriteAsync(cts.Token), cts.Token);
            AssertSynchronouslyCanceled(w.WriteAsync(42, cts.Token), cts.Token);
        }
Ejemplo n.º 3
0
        public async Task TryWrite_AfterComplete()
        {
            IWritableChannel <int> c = Channel.WriteToStream <int>(new MemoryStream());

            Assert.True(c.TryComplete());
            Assert.False(c.TryWrite(42));
            AssertSynchronousFalse(c.WaitToWriteAsync());
            await Assert.ThrowsAnyAsync <InvalidOperationException>(() => c.WriteAsync(42));

            Assert.False(c.TryComplete());
        }
Ejemplo n.º 4
0
 public override Task <bool> WaitAsync(CancellationToken cancellationToken)
 {
     return(_channel.WaitToWriteAsync(cancellationToken));
 }