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); } }
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); }
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()); }
public override Task <bool> WaitAsync(CancellationToken cancellationToken) { return(_channel.WaitToWriteAsync(cancellationToken)); }