Пример #1
0
        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());
        }
Пример #2
0
        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();
            });
        }
Пример #3
0
 public override void SmallCoffee()
 {
     Console.WriteLine("IdleState: make small coffee");
     CoffeeMachine.TransitionTo(new WorkingState(5));
 }
Пример #4
0
 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()));
        }