Ejemplo n.º 1
0
        public async Task t3_async_can_await_events()
        {
            Workflow w = new Workflow();

            // Simulate people working on workflow (on separate thread)
            Task.Run(() =>
                {
                    Thread.Sleep(100);
                    w.ManagerReview("Looks great! -manager");
                    w.LegalReview("We're covered. -legal");
                    w.Approve();
                });

            // Business logic separated from workflow capabilities
            Console.WriteLine("Awaiting reviews");
            await Task.WhenAll(
                w.WhenLegalReviewed(),
                w.WhenManagerReviewed());
            Console.WriteLine("Have all reviews");

            Console.WriteLine("Awaiting approval");
            await w.WhenApproved();
            Console.WriteLine("Have final approval, workflow finished");
        }