Ejemplo n.º 1
0
        public static async Task BroadcastCancellation()
        {
            var key1 = Guid.NewGuid();
            var key2 = Guid.NewGuid();

            var source    = new AsyncCorrelationSource <Guid, int>(10);
            var listener1 = source.WaitAsync(key1);
            var listener2 = source.WaitAsync(key2);

            source.PulseAll(new CancellationToken(true));

            await ThrowsAnyAsync <OperationCanceledException>(async() => await listener1);
            await ThrowsAnyAsync <OperationCanceledException>(async() => await listener2);
        }
Ejemplo n.º 2
0
        public static async Task BroadcastResult()
        {
            var key1 = Guid.NewGuid();
            var key2 = Guid.NewGuid();

            var source    = new AsyncCorrelationSource <Guid, int>(10);
            var listener1 = source.WaitAsync(key1);
            var listener2 = source.WaitAsync(key2);

            source.PulseAll(42);

            Equal(42, await listener1);
            Equal(42, await listener2);
        }
Ejemplo n.º 3
0
        public static async Task BroadcastException()
        {
            var key1 = Guid.NewGuid();
            var key2 = Guid.NewGuid();

            var source    = new AsyncCorrelationSource <Guid, int>(10);
            var listener1 = source.WaitAsync(key1);
            var listener2 = source.WaitAsync(key2);

            source.PulseAll(new ArithmeticException());

            await ThrowsAsync <ArithmeticException>(async() => await listener1);
            await ThrowsAsync <ArithmeticException>(async() => await listener2);
        }