Ejemplo n.º 1
0
 public void Cancel(out CompletionData completionData)
 {
     Complete(out completionData);
     _canceledState = completionData.Completion == null ?
                      CanceledState.CancellationPreRequested :
                      CanceledState.CancellationRequested;
 }
Ejemplo n.º 2
0
        public bool ObserveCancelation()
        {
            if (_canceledState == CanceledState.NotCanceled)
            {
                return(false);
            }

            bool isPrerequested = _canceledState == CanceledState.CancellationPreRequested;

            if (_canceledState >= CanceledState.CancellationPreRequested)
            {
                _canceledState = CanceledState.CancellationObserved;

                // Do not reset awaitable if we were not awaiting in the first place
                if (!isPrerequested)
                {
                    Reset();
                }

                _cancellationToken.ThrowIfCancellationRequested();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public Action Cancel()
        {
            Action action = Complete();

            _canceledState = action == null ?
                             CanceledState.CancellationPreRequested :
                             CanceledState.CancellationRequested;
            return(action);
        }
Ejemplo n.º 4
0
 public PipeAwaitable(bool completed, bool useSynchronizationContext)
 {
     _canceledState             = CanceledState.NotCanceled;
     _completion                = completed ? s_awaitableIsCompleted : s_awaitableIsNotCompleted;
     _completionState           = null;
     _synchronizationContext    = null;
     _executionContext          = null;
     _useSynchronizationContext = useSynchronizationContext;
 }
Ejemplo n.º 5
0
        public void Reset()
        {
            if (ReferenceEquals(_state, _awaitableIsCompleted) &&
                _canceledState < CanceledState.CancellationPreRequested)
            {
                _state = _awaitableIsNotCompleted;
            }

            // Change the state from observed -> not cancelled.
            // We only want to reset the cancelled state if it was observed
            if (_canceledState == CanceledState.CancellationObserved)
            {
                _canceledState = CanceledState.NotCanceled;
            }
        }
Ejemplo n.º 6
0
        private AbstractState CreateAbstractState(Shipping m_Parent)
        {
            AbstractState _ret = null;

            switch (m_Parent.ShippingState2.GetValueOrDefault(GetDefaultValue(m_Parent)))
            {
            case ShippingState2.Cancelation:
                _ret = new CancelationState(this);
                break;

            case ShippingState2.Canceled:
                _ret = new CanceledState(this);
                break;

            case ShippingState2.Completed:
                _ret = new CompletedState(this);
                break;

            case ShippingState2.Confirmed:
                _ret = new ConfirmedState(this);
                break;

            case ShippingState2.Creation:
                _ret = new CreationState(this);
                break;

            case ShippingState2.Delayed:
                _ret = new DelayedState(this);
                break;

            case ShippingState2.LackOfData:
                _ret = new LackOfDataState(this);
                break;

            case ShippingState2.Left:
                _ret = new LeftState(this);
                break;

            case ShippingState2.Started:
                _ret = new StartedState(this);
                break;

            case ShippingState2.Waiting:
                _ret = new WaitingState(this);
                break;
            }
            return(_ret);
        }
Ejemplo n.º 7
0
        public void Reset()
        {
            if (ReferenceEquals(_completion, s_awaitableIsCompleted) &&
                _canceledState < CanceledState.CancellationPreRequested)
            {
                _completion             = s_awaitableIsNotCompleted;
                _completionState        = null;
                _synchronizationContext = null;
                _executionContext       = null;
            }

            // Change the state from observed -> not cancelled.
            // We only want to reset the cancelled state if it was observed
            if (_canceledState == CanceledState.CancelationObserved)
            {
                _canceledState = CanceledState.NotCanceled;
            }
        }
        public void Complete(out CompletionData completionData)
        {
            Action <object> currentCompletion = _completion;
            object          currentState      = _completionState;

            _completion      = s_awaitableIsCompleted;
            _completionState = null;

            completionData = default;

            if (!ReferenceEquals(currentCompletion, s_awaitableIsCompleted) &&
                !ReferenceEquals(currentCompletion, s_awaitableIsNotCompleted))
            {
                completionData = new CompletionData(currentCompletion, currentState, _executionContext, _synchronizationContext);
            }
            else if (_canceledState == CanceledState.CancellationRequested)
            {
                // Make sure we won't reset the awaitable in ObserveCancellation
                // If Complete happens in between Cancel and ObserveCancellation
                _canceledState = CanceledState.CancellationPreRequested;
            }
        }
Ejemplo n.º 9
0
 public PipeAwaitable(bool completed)
 {
     _canceledState = CanceledState.NotCanceled;
     _state         = completed ? _awaitableIsCompleted : _awaitableIsNotCompleted;
 }
Ejemplo n.º 10
0
 internal override void TrySetCanceled(out State state, out Func <bool> postscript, CancellationToken cancellationToken)
 {
     state      = new CanceledState(cancellationToken);
     postscript = TryPostscript;
 }
Ejemplo n.º 11
0
 internal override void SetCanceled(out State state, out Action postscript, CancellationToken cancellationToken)
 {
     state      = new CanceledState(cancellationToken);
     postscript = Postscript;
 }