示例#1
0
 private void CancelSelf()
 {
     _lifecycleState = LifecycleState.Canceled;
     _subscriber     = null;
     _onError        = null;
     _demand         = 0L;
 }
示例#2
0
        /// <summary>
        /// Terminate the stream with failure. After that you are not allowed to
        /// call <see cref="OnNext"/>, <see cref="OnError"/> and <see cref="OnComplete"/>.
        /// </summary>
        /// <param name="cause">TBD</param>
        /// <exception cref="IllegalStateException">
        /// This exception is thrown for a number of reasons. These include:
        /// <dl>
        ///   <dt>when in the <see cref="LifecycleState.ErrorEmitted"/> state</dt>
        ///   <dd>This exception is thrown when this <see cref="ActorPublisher{T}"/> has already terminated due to an error.</dd>
        ///   <dt>when in the <see cref="LifecycleState.Completed"/> or <see cref="LifecycleState.CompleteThenStop"/> state</dt>
        ///   <dd>This exception is thrown when this <see cref="ActorPublisher{T}"/> has already completed.</dd>
        /// </dl>
        /// </exception>
        public void OnError(Exception cause)
        {
            switch (_lifecycleState)
            {
            case LifecycleState.Active:
            case LifecycleState.PreSubscriber:
                _lifecycleState = LifecycleState.ErrorEmitted;
                _onError        = new OnErrorBlock(cause, false);
                if (_subscriber != null)
                {
                    // otherwise onError will be called when the subscription arrives
                    try
                    {
                        ReactiveStreamsCompliance.TryOnError(_subscriber, cause);
                    }
                    finally
                    {
                        _subscriber = null;
                    }
                }
                break;

            case LifecycleState.ErrorEmitted: throw new IllegalStateException("OnError must only be called once");

            case LifecycleState.Completed:
            case LifecycleState.CompleteThenStop: throw new IllegalStateException("OnError must not be called after OnComplete");

            case LifecycleState.Canceled: break;
            }
        }
示例#3
0
        /// <summary>
        /// <para>
        /// Terminate the stream with failure. After that you are not allowed to
        /// call <see cref="OnNext"/>, <see cref="OnError"/> and <see cref="OnComplete"/>.
        /// </para>
        /// <para>
        /// After signalling the Error the Actor will then stop itself as it has completed the protocol.
        /// When <see cref="OnError"/> is called before any <see cref="ISubscriber{T}"/> has had the chance to subscribe
        /// to this <see cref="ActorPublisher{T}"/> the error signal (and therefore stopping of the Actor as well)
        /// will be delayed until such <see cref="ISubscriber{T}"/> arrives.
        /// </para>
        /// </summary>
        /// <param name="cause">TBD</param>
        public void OnErrorThenStop(Exception cause)
        {
            switch (_lifecycleState)
            {
            case LifecycleState.Active:
            case LifecycleState.PreSubscriber:
                _lifecycleState = LifecycleState.ErrorEmitted;
                _onError        = new OnErrorBlock(cause, stop: true);
                if (_subscriber != null)
                {
                    // otherwise onError will be called when the subscription arrives
                    try
                    {
                        ReactiveStreamsCompliance.TryOnError(_subscriber, cause);
                    }
                    finally
                    {
                        Context.Stop(Self);
                    }
                }
                break;

            default: OnError(cause); break;
            }
        }
示例#4
0
        /// <summary>
        /// <para>
        /// Complete the stream. After that you are not allowed to
        /// call <see cref="OnNext"/>, <see cref="OnError"/> and <see cref="OnComplete"/>.
        /// </para>
        /// <para>
        /// After signalling completion the Actor will then stop itself as it has completed the protocol.
        /// When <see cref="OnComplete"/> is called before any <see cref="ISubscriber{T}"/> has had the chance to subscribe
        /// to this <see cref="ActorPublisher{T}"/> the completion signal (and therefore stopping of the Actor as well)
        /// will be delayed until such <see cref="ISubscriber{T}"/> arrives.
        /// </para>
        /// </summary>
        public void OnCompleteThenStop()
        {
            switch (_lifecycleState)
            {
            case LifecycleState.Active:
            case LifecycleState.PreSubscriber:
                _lifecycleState = LifecycleState.CompleteThenStop;
                _onError        = null;
                if (_subscriber != null)
                {
                    // otherwise onComplete will be called when the subscription arrives
                    try
                    {
                        ReactiveStreamsCompliance.TryOnComplete(_subscriber);
                    }
                    finally
                    {
                        Context.Stop(Self);
                    }
                }
                break;

            default: OnComplete(); break;
            }
        }