public static void Execute() { var coffeeMachine = new CoffeeMachine(); Task.Delay(TimeSpan.FromSeconds(1)).ContinueWith(x => coffeeMachine.LargeCoffee()); Task.Delay(TimeSpan.FromSeconds(7)).ContinueWith(x => coffeeMachine.LargeCoffee()); Task.Delay(TimeSpan.FromSeconds(9)).ContinueWith(x => coffeeMachine.SmallCoffee()); Task.Delay(TimeSpan.FromSeconds(12)).ContinueWith(x => coffeeMachine.SmallCoffee()); }
protected override void OnNewContext() { _cancellationTokenSource = new CancellationTokenSource(); Task task = Task.Delay(TimeSpan.FromSeconds(_time), _cancellationTokenSource.Token); task.ContinueWith(x => { CoffeeMachine.TransitionTo(new IdleState()); _cancellationTokenSource.Dispose(); }); }
public override void SmallCoffee() { Console.WriteLine("IdleState: make small coffee"); CoffeeMachine.TransitionTo(new WorkingState(5)); }
public override void LargeCoffee() { Console.WriteLine("IdleState: make large coffee"); CoffeeMachine.TransitionTo(new WorkingState(8)); }
protected override void OnNewContext() { var task = Task.Delay(TimeSpan.FromSeconds(5)); task.ContinueWith(x => CoffeeMachine.TransitionTo(new IdleState())); }