Пример #1
0
        /// <summary>
        /// Sends an element to the stream subscriber. You are allowed to send as many elements
        /// as have been requested by the stream subscriber. This amount can be inquired with
        /// <see cref="TotalDemand"/>. It is only allowed to use <see cref="OnNext"/> when
        /// <see cref="IsActive"/> and <see cref="TotalDemand"/> &gt; 0,
        /// otherwise <see cref="OnNext"/> will throw <see cref="IllegalStateException"/>.
        /// </summary>
        /// <param name="element">TBD</param>
        /// <exception cref="IllegalStateException">
        /// This exception is thrown for a number of reasons. These include:
        /// <dl>
        ///   <dt>when in the <see cref="LifecycleState.Active"/> or <see cref="LifecycleState.PreSubscriber"/> state</dt>
        ///   <dd>This exception is thrown when the <see cref="ActorPublisher{T}"/> has zero <see cref="TotalDemand"/>.</dd>
        ///   <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 OnNext(T element)
        {
            switch (_lifecycleState)
            {
            case LifecycleState.Active:
            case LifecycleState.PreSubscriber:
                if (_demand > 0)
                {
                    _demand--;
                    ReactiveStreamsCompliance.TryOnNext(_subscriber, element);
                }
                else
                {
                    throw new IllegalStateException(
                              "OnNext is not allowed when the stream has not requested elements, total demand was 0");
                }
                break;

            case LifecycleState.ErrorEmitted:
                throw new IllegalStateException("OnNext must not be called after OnError");

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

            case LifecycleState.Canceled: break;
            }
        }
Пример #2
0
 private void OnNext(T element)
 {
     _downstreamDemand--;
     ReactiveStreamsCompliance.TryOnNext(_subscriber, element);
 }