public void Cancel(out CompletionData completionData) { Complete(out completionData); _canceledState = completionData.Completion == null ? CanceledState.CancellationPreRequested : CanceledState.CancellationRequested; }
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); }
public Action Cancel() { Action action = Complete(); _canceledState = action == null ? CanceledState.CancellationPreRequested : CanceledState.CancellationRequested; return(action); }
public PipeAwaitable(bool completed, bool useSynchronizationContext) { _canceledState = CanceledState.NotCanceled; _completion = completed ? s_awaitableIsCompleted : s_awaitableIsNotCompleted; _completionState = null; _synchronizationContext = null; _executionContext = null; _useSynchronizationContext = useSynchronizationContext; }
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; } }
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); }
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; } }
public PipeAwaitable(bool completed) { _canceledState = CanceledState.NotCanceled; _state = completed ? _awaitableIsCompleted : _awaitableIsNotCompleted; }
internal override void TrySetCanceled(out State state, out Func <bool> postscript, CancellationToken cancellationToken) { state = new CanceledState(cancellationToken); postscript = TryPostscript; }
internal override void SetCanceled(out State state, out Action postscript, CancellationToken cancellationToken) { state = new CanceledState(cancellationToken); postscript = Postscript; }