Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to make a meal");
            Console.ReadKey();

            Kitchen kitchen = new Kitchen();
            Potato  potato  = new Potato();

            // Synchronously peel a potato
            // Can't do other stuff while peeling a potato
            potato.Peel();

            //Asynchronously drop the fries
            // Async so I can do other things
            var fries = kitchen.FryPotatoesAsync(potato);

            // Synchronously assemble a burger WHILE fries are cooking
            var hamburger = kitchen.AssembleBurger();

            Console.WriteLine("Doing other stuff");

            kitchen.ServeMeal(fries.Result, hamburger);

            Console.ReadKey();
        }
Пример #2
0
        public async Task <Fries> FryPotatoesAsync(Potato potato)
        {
            if (potato.IsPeeled)
            {
                PrettyPrint("Dropping in the fries", 14);
                // await, move on bro, but it's local to the method
                await Task.Delay(5000);

                PrettyPrint("Fries are frying", 14);
                await Task.Delay(5000);

                PrettyPrint("DING! Fries are done!", 14);
                return(new Fries(potato));
            }
            else
            {
                Console.WriteLine("This potato isn't peeled");
                return(null);
            }
        }
 public Fries(Potato potato)
 {
 }