public void EnqueueTransition(Enum transition, object data = null) { if (Equals(transition, StateMachineBaseTransition.Cancel)) { throw new NotSupportedException("use \"StateMachine.Cancel()\" instead of enqueueing a cancel transition"); } lock (_commandEnqueueLock) { _commandQueue.Add(StateMachineCommand.Transition(transition, data)); } }
public void Cancel(string reason = "undefined") { Logger.LogError($"cancelling Statemaschine with reason: {reason}"); _transitionCts.Cancel(); lock (new[] { _commandEnqueueLock, _commandDequeueLock }) { while (_commandQueue.Count > 0) { _commandQueue.Take(); } _commandQueue.Add(StateMachineCommand.Transition(StateMachineBaseTransition.Cancel)); _transitionCts = new CancellationTokenSource(); } }