Example #1
0
 private async Task FillBuyerQueue(BuyersQueue BuyerQueue)
 {
     //In a "real" program we will check which Bbuyer finished his shopping, before adding him to the queue
     for (int i = 0; i <= NUM_OF_BUYERS; i++)
     {
         await _buyersQueue.EnqueueBuyer(new Buyer()
         {
             FirstName = $"F{i}", LastName = $"L{i}", StartWaiting = DateTime.Now
         });
     }
     _buyersQueue.SignForNoMoreBuyers(); //must sign that there are no more buyers that can join the queue
 }
Example #2
0
        public async Task HandleQueue(BuyersQueue buyersQueue)
        {
            Console.WriteLine($"{ToString()} started working");

            bool stillHasBuyers = true;

            while (stillHasBuyers)
            {
                Buyer buyer = buyersQueue.DequeueCutomer(); //dequeue a buyer
                if (buyer != null)
                {
                    await HandleBuyer(buyer);
                }
                else if (buyersQueue.HasNoMoreBuyers) //no more buyers in the supermarket
                {
                    stillHasBuyers = false;
                }
            }

            Console.WriteLine($"{ToString()} ended working");
        }