Ejemplo n.º 1
0
        public async Task QueueAsyncFunction()
        {
            // Assign

            var queue = new SerialQueue();
            var list  = new List <int>();
            var tasks = new List <Task>();
            var range = Enumerable.Range(0, 100);

            // Act

            foreach (var number in range)
            {
                tasks.Add(queue.EnqueueAsyncFunction(async() =>
                {
                    await Task.Delay(50);
                    list.Add(number);
                }));
            }

            await Task.WhenAll(tasks);

            // Assert

            Assert.True(range.SequenceEqual(list));
        }