Ejemplo n.º 1
0
        public void TestCompleteSuccessfullyWithFasterProducer()
        {
            AsyncEnumerator <int> enumerator = new AsyncEnumerator <int>();
            var consumer = enumerator.Consumer;

            int         cnt        = 0;
            List <Task> yieldTasks = new List <Task>();

            yieldTasks.Add(consumer.YieldAsync(cnt++));
            yieldTasks.Add(consumer.YieldAsync(cnt++));
            yieldTasks.Add(consumer.YieldAsync(cnt++));

            consumer.Complete();

            enumerator.ProceedToCompletion();

            Task.WaitAll(yieldTasks.ToArray());

            try
            {
                consumer.YieldAsync(1); // must raise exception
            }
            catch (InvalidOperationException)
            { }
        }