Beispiel #1
0
            public Logic(IdleInject <TIn, TOut> stage) : base(stage.Shape)
            {
                _stage        = stage;
                _nextDeadline = DateTime.UtcNow.Ticks + _stage._timeout.Ticks;

                SetHandler(_stage._in, this);
                SetHandler(_stage._out, this);
            }
Beispiel #2
0
            public Logic(IdleInject <TIn, TOut> stage) : base(stage.Shape)
            {
                _stage        = stage;
                _nextDeadline = DateTime.UtcNow + _stage._timeout;

                SetHandler(_stage._in, onPush: () =>
                {
                    _nextDeadline = DateTime.UtcNow + _stage._timeout;
                    CancelTimer(IdleTimer);
                    if (IsAvailable(_stage._out))
                    {
                        Push(_stage._out, Grab(_stage._in));
                        Pull(_stage._in);
                    }
                },
                           onUpstreamFinish: () =>
                {
                    if (!IsAvailable(_stage._in))
                    {
                        CompleteStage();
                    }
                });

                SetHandler(_stage._out, onPull: () =>
                {
                    if (IsAvailable(_stage._in))
                    {
                        Push(_stage._out, Grab(_stage._in));
                        if (IsClosed(_stage._in))
                        {
                            CompleteStage();
                        }
                        else
                        {
                            Pull(_stage._in);
                        }
                    }
                    else
                    {
                        var timeLeft = _nextDeadline - DateTime.UtcNow;
                        if (timeLeft <= TimeSpan.Zero)
                        {
                            _nextDeadline = DateTime.UtcNow + _stage._timeout;
                            Push(_stage._out, _stage._inject());
                        }
                        else
                        {
                            ScheduleOnce(IdleTimer, timeLeft);
                        }
                    }
                });
            }
Beispiel #3
0
            public Logic(IdleInject <TIn, TOut> stage) : base(stage.Shape)
            {
                _stage        = stage;
                _nextDeadline = DateTime.UtcNow.Ticks + _stage._timeout.Ticks;

                SetHandler(_stage._in, onPush: () =>
                {
                    _nextDeadline = DateTime.UtcNow.Ticks + _stage._timeout.Ticks;
                    CancelTimer(Timers.GraphStageLogicTimer);
                    if (IsAvailable(_stage._out))
                    {
                        Push(_stage._out, Grab(_stage._in));
                        Pull(_stage._in);
                    }
                },
                           onUpstreamFinish: () =>
                {
                    if (!IsAvailable(_stage._in))
                    {
                        CompleteStage();
                    }
                });

                SetHandler(_stage._out, onPull: () =>
                {
                    if (IsAvailable(_stage._in))
                    {
                        Push(_stage._out, Grab(_stage._in));
                        if (IsClosed(_stage._in))
                        {
                            CompleteStage();
                        }
                        else
                        {
                            Pull(_stage._in);
                        }
                    }
                    else
                    {
                        var time = DateTime.UtcNow.Ticks;
                        if (_nextDeadline - time < 0)
                        {
                            _nextDeadline = time + _stage._timeout.Ticks;
                            Push(_stage._out, _stage._inject());
                        }
                        else
                        {
                            ScheduleOnce(Timers.GraphStageLogicTimer, TimeSpan.FromTicks(_nextDeadline - time));
                        }
                    }
                });
            }