Example #1
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="inputCount">TBD</param>
        /// <param name="bufferSize">TBD</param>
        /// <param name="pump">TBD</param>
        protected InputBunch(int inputCount, int bufferSize, IPump pump)
        {
            _inputCount = inputCount;

            _states = new State[inputCount];
            _inputs = new BatchingInputBuffer[inputCount];
            for (var i = 0; i < inputCount; i++)
            {
                _inputs[i] = new AnonymousBatchingInputBuffer(bufferSize, pump, i, this);
            }

            AllOfMarkedInputs = new LambdaTransferState(
                isCompleted: () => _markedDepleted > 0,
                isReady: () => _markedPending == _markCount);

            AnyOfMarkedInputs = new LambdaTransferState(
                isCompleted: () => _markedDepleted == _markCount && _markedPending == 0,
                isReady: () => _markedPending > 0);

            // FIXME: Eliminate re-wraps
            SubReceive = new SubReceive(msg => msg.Match()
                                        .With <FanIn.OnSubscribe>(subscribe => _inputs[subscribe.Id].SubReceive.CurrentReceive(new Actors.OnSubscribe(subscribe.Subscription)))
                                        .With <FanIn.OnNext>(next =>
            {
                var id = next.Id;
                if (IsMarked(id) && !IsPending(id))
                {
                    _markedPending++;
                }
                Pending(id, on: true);
                _receivedInput = true;
                _inputs[id].SubReceive.CurrentReceive(new Actors.OnNext(next.Element));
            })
                                        .With <FanIn.OnComplete>(complete =>
            {
                var id = complete.Id;
                if (!IsPending(id))
                {
                    if (IsMarked(id) && !IsDepleted(id))
                    {
                        _markedDepleted++;
                    }
                    Depleted(id, on: true);
                    OnDepleted(id);
                }

                RegisterCompleted(id);
                _inputs[id].SubReceive.CurrentReceive(Actors.OnComplete.Instance);

                if (!_receivedInput && IsAllCompleted)
                {
                    OnCompleteWhenNoInput();
                }
            })
                                        .With <FanIn.OnError>(error => OnError(error.Id, error.Cause))
                                        .WasHandled);
        }
Example #2
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="precondition">TBD</param>
 /// <param name="action">TBD</param>
 public TransferPhase(TransferState precondition, Action action) : this()
 {
     Precondition = precondition;
     Action       = action;
 }
Example #3
0
 public TransferState And(TransferState other)
     => new LambdaTransferState(() => IsReady && other.IsReady, () => IsCompleted || other.IsCompleted);
Example #4
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="other">TBD</param>
 /// <returns>TBD</returns>
 public TransferState And(TransferState other)
 => new LambdaTransferState(() => IsReady && other.IsReady, () => IsCompleted || other.IsCompleted);
Example #5
0
 public TransferPhase(TransferState precondition, Action action) : this()
 {
     Precondition = precondition;
     Action = action;
 }