예제 #1
0
        /// <summary>TODO</summary>
        public static async Task <Unit> ExecuteTrafficLight <T>
            (this ITrafficLight <T> e)
        {
            e.ContractedNotNull("e");
            Contract.Ensures(Contract.Result <Task <Unit> >() != null); // not supported for async/await
            try {
                var trafficLightState = await LightStates <T> .Start(e)(e);

                while (trafficLightState != null)
                {
                    trafficLightState = await trafficLightState()(e);
                }
            } catch (OperationCanceledException) {; }
            return(Unit._);
        }
예제 #2
0
        //[Pure]
        internal static Reader <ITrafficLight <T>, Task <LightStates <T> .TrafficLightState> > GetState <T>(
            this LightStates <T> .Transition transition,
            int delayTenthsSeconds,
            IO <Unit> action
            )
        {
            transition.ContractedNotNull("transition");
            Contract.Ensures(Contract.Result <Reader <ITrafficLight <T>, Task <LightStates <T> .TrafficLightState> > >() != null);

            return(e => from _ in (from _ in action
                                   select Task.Delay(TimeSpan.FromMilliseconds(100 * delayTenthsSeconds)
                                                     , e.CancellationToken)
                                   ).Invoke()
                   select new LightStates <T> .TrafficLightState(() => transition(e)));
        }
예제 #3
0
 private async Task <Unit> StartLights()
 {
     return(await LightStates.ExecuteTrafficLight <Image>(_trafficLight));
 }