コード例 #1
0
        public static async Task <TrafficLightStateFunction> Amber(TrafficLightState state)
        {
            state.Red   = false;
            state.Amber = true;
            state.Green = false;

            Console.WriteLine("AMBER");

            await Task.Delay(TimeSpan.FromSeconds(3));

            return(Red);
        }
コード例 #2
0
        public static async Task <TrafficLightStateFunction> Green(TrafficLightState state)
        {
            state.Red   = false;
            state.Amber = false;
            state.Green = true;

            Console.WriteLine("GREEN");

            await Task.Delay(TimeSpan.FromSeconds(12));

            return(Amber);
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            Task.Run(async() =>
            {
                var state = new TrafficLightState();
                TrafficLightStateFunction stateFunction = Red;

                while (stateFunction != null)
                {
                    stateFunction = await stateFunction(state);
                }
            });

            Console.ReadKey();
        }