Beispiel #1
0
 protected bool DownstreamRunning(object message)
 {
     if (message is SubscribePending)
     {
         SubscribePending(ExposedPublisher.TakePendingSubscribers());
     }
     else if (message is RequestMore)
     {
         var requestMore = (RequestMore)message;
         if (requestMore.Demand < 1)
         {
             Error(ReactiveStreamsCompliance.NumberOfElementsInRequestMustBePositiveException);
         }
         else
         {
             DownstreamDemand += requestMore.Demand;
             if (DownstreamDemand < 1)
             {
                 DownstreamDemand = long.MaxValue;   // Long overflow, Reactive Streams Spec 3:17: effectively unbounded
             }
             Pump.Pump();
         }
     }
     else if (message is Cancel)
     {
         IsDownstreamCompleted = true;
         ExposedPublisher.Shutdown(new NormalShutdownException(string.Empty));
         Pump.Pump();
     }
     else
     {
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="message">TBD</param>
        /// <returns>TBD</returns>
        protected bool DownstreamRunning(object message)
        {
            if (message is SubscribePending)
            {
                SubscribePending();
            }
            else if (message is RequestMore)
            {
                var requestMore = (RequestMore)message;
                MoreRequested((ActorSubscriptionWithCursor <T>)requestMore.Subscription, requestMore.Demand);
                _pump.Pump();
            }
            else if (message is Cancel)
            {
                var cancel = (Cancel)message;
                UnregisterSubscription((ActorSubscriptionWithCursor <T>)cancel.Subscription);
                _pump.Pump();
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        protected virtual void EnqueueInputElement(object element)
        {
            if (IsOpen)
            {
                if (_inputBufferElements == Count)
                {
                    throw new IllegalStateException("Input buffer overrun");
                }
                _inputBuffer[(_nextInputElementCursor + _inputBufferElements) & _indexMask] = element;
                _inputBufferElements++;
            }

            Pump.Pump();
        }
Beispiel #4
0
 public void Brew()
 {
     _heater.On();
     _pump.Pump();
     Console.WriteLine(" [_]P coffee! [_]P ");
     _heater.Off();
 }
Beispiel #5
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="message">TBD</param>
        /// <returns>TBD</returns>
        protected bool DownstreamRunning(object message)
        {
            switch (message)
            {
            case SubscribePending _:
                SubscribePending();
                return(true);

            case RequestMore requestMore:
                MoreRequested((ActorSubscriptionWithCursor <T>)requestMore.Subscription, requestMore.Demand);
                _pump.Pump();
                return(true);

            case Cancel cancel:
                UnregisterSubscription((ActorSubscriptionWithCursor <T>)cancel.Subscription);
                _pump.Pump();
                return(true);

            default:
                return(false);
            }
        }
Beispiel #6
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="self">TBD</param>
        public static void GotUpstreamSubscription(this IPump self)
        {
            if (self.TransferState is WaitingForUpstreamSubscription)
            {
                var t = (WaitingForUpstreamSubscription)self.TransferState;
                if (t.Remaining == 1)
                {
                    self.TransferState = t.AndThen.Precondition;
                    self.CurrentAction = t.AndThen.Action;
                }
                else
                {
                    self.TransferState = new WaitingForUpstreamSubscription(t.Remaining - 1, t.AndThen);
                }
            }

            self.Pump();
        }