/// <summary> /// Stops the state associated with the token. The token must be one that was /// returned when the state was started. /// </summary> /// <param name="token">The token of the state to stop.</param> /// <exception cref="ArgumentNullException">token</exception> /// <exception cref="InvalidOperationException"> /// The given token is not from this state tracker /// or /// the given token is not active /// </exception> public void StopState(IStateToken <TStateData> token) { if (token == null) { throw new ArgumentNullException("token"); } if (!(token is StateToken)) { throw new InvalidOperationException("The given token is not from this state tracker"); } if (!activeTokens.Contains((StateToken)token)) { throw new InvalidOperationException("The given token is not active"); } activeTokens.Remove((StateToken)token); if (!IsActive) { if (OnStateInactive != null) { OnStateInactive(); } } }
private async UniTask OwnToken(IStateToken token) { var result = token.TakeOwnership(this); _token = result ? token : null; _isStateActive = result; await ExecuteAsync(token.Context); }
private bool OwnToken(IStateToken token) { var result = token.TakeOwnership(this); if (result && autoRestart) { _state.ExitState(); } _token = result ? token : null; _isStateActive = result; return(result); }
/// <summary> /// Stops the state associated with the token. The token must be one that was /// returned when the state was started. /// </summary> /// <param name="token">The token of the state to stop.</param> /// <exception cref="ArgumentNullException">token</exception> /// <exception cref="InvalidOperationException"> /// The given token is not from this state tracker /// or /// the given token is not active /// </exception> public void StopState(IStateToken <TStateData> token) { if (token == null) { throw new ArgumentNullException("token"); } if (!clocks.ContainsKey(token)) { throw new InvalidOperationException("The token was not obtain by this tracker or already has been stopped."); } clocks.Remove(token); tracker.StopState(token); tokensCopy = ActiveTokens.ToList(); }
/// <summary> /// Stops the state associated with the token. The token must be one that was /// returned when the state was started. /// </summary> /// <param name="token">The token of the state to stop.</param> /// <exception cref="ArgumentNullException">token</exception> /// <exception cref="InvalidOperationException"> /// The given token is not from this state tracker /// or /// the given token is not active /// </exception> /// <exception cref="InvalidOperationException">Invalid token</exception> public void StopState(IStateToken <TStateData> token) { var timeState = token as TimeStateWrapper; if (timeState == null) { // This can happen when a user somehow // obtains a IStateToken<TStateData> // that was not returned by this tracker. throw new InvalidOperationException("Invalid token"); } if (!tracker.ActiveTokens.Contains(timeState.token)) { throw new InvalidOperationException("The token is not active."); } tracker.StopState(timeState.token); }
private IStateToken CreateToken() { if (_token != null) { return(_token); } _token = new FlowStateToken() .AddTo(TokenLifeTime); if (connectWithGrphContext) { _token.Context .Connect(this.Context) .AddTo(_token.LifeTime); } LifeTime.AddDispose(_token); LifeTime.AddCleanUpAction(() => _token = null); return(_token); }
public async UniTask ExitAsync() { _isStateActive = false; _token = null; await _asyncStateProxy.ExitAsync(); }
public void StopState() { _isStateActive = false; _token = null; _state.ExitState(); }
private void OnActivateState(IStateToken token) { _state.Execute(token.Context) .Subscribe() .AddTo(_state.LifeTime); }