Example #1
0
 static void Writer <T>(CoyoteAsyncBuffer <T> queue, IEnumerable <T> items, string taskname)
 {
     foreach (var item in items)
     {
         queue.Enqueue(item);
     }
 }
Example #2
0
        public static async Task Execute_Buffer_TenReadersAndWriters(ICoyoteRuntime runtime)
        {
            Action <string> log = s => runtime.Logger.WriteLine(s);

            var generator           = Generator.Create();
            var numConsumerProducer = generator.NextInteger(10) + 1;
            var numConsumers        = numConsumerProducer;
            var numProducers        = numConsumerProducer;

            log($"Testing Queue with {numConsumerProducer} consumers and producers");
            var queue = new CoyoteAsyncBuffer <int>(1000, runtime.Logger);

            var tasks =
                Chop(RandomStream(generator, 100), numProducers)
                .Select((x, i) => { var t = Task.Run(() => Writer(queue, x, $"Task{i}")); i++; return(t); })
                .ToList();

            for (int i = 0; i < numProducers; i++)
            {
                tasks.Add(Task.Run(() => Reader(queue, "")));
            }

            await Task.WhenAll(tasks.ToArray());
        }
Example #3
0
 static async Task <T> Reader <T>(CoyoteAsyncBuffer <T> queue, string taskname)
 {
     return(await queue.Dequeue());
 }