/// <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._); }
//[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))); }
private async Task <Unit> StartLights() { return(await LightStates.ExecuteTrafficLight <Image>(_trafficLight)); }