Esempio n. 1
0
        void Internal.ICancelDelegate.Invoke(Internal.ICancelValueContainer valueContainer)
        {
            CancelCallbacks();
            CancelProgressListeners();

            object currentValue = _valueOrPrevious;

            _valueOrPrevious = valueContainer;
            valueContainer.Retain();

            // This might be called synchronously when it's registered to an already canceled token. In that case, _valueOrPrevious will be null.
            if (currentValue == null)
            {
                return;
            }

            // Otherwise, the promise is either waiting for its previous, or it's in the handle queue.
            if (currentValue is Promise)
            {
                // Remove this from previous' next branches.
                ((Internal.ITreeHandleableCollection)currentValue).Remove(this);
                Internal.AddToHandleQueueBack(this);
            }
            else
            {
                // Rejection maybe wasn't caught.
                ((Internal.IValueContainer)currentValue).ReleaseAndMaybeAddToUnhandledStack();
                // Don't add to handle queue since it's already in it.
            }
        }