Ejemplo n.º 1
0
            private void DoSubscribeTask(bool recovery = false)
            {
                _context.TraceSource.StartWith_Subscribing(_context.InstanceId);

                var subscription = default(ISubscription);

                try
                {
                    subscription = Params._source.Subscribe(this);

                    if (recovery)
                    {
                        SubscriptionInitializeVisitor.Subscribe(subscription);
                        SubscriptionInitializeVisitor.SetContext(subscription, _context);
                    }
                    else
                    {
                        SubscriptionInitializeVisitor.Initialize(subscription, _context);
                    }
                }
                catch (Exception ex)
                {
                    subscription?.Dispose();

                    DoSchedule(new ActionTask(() =>
                    {
                        Output.OnError(ex);
                        Dispose();
                    }));

                    return;
                }

                _subscription.Subscription = subscription;
            }
Ejemplo n.º 2
0
            protected void DoSubscribeTask(bool recovery = false)
            {
                EnsureResourceManagement(recovery);

                if (!recovery)
                {
                    // Needs to happen before subscribing to the source, so an inner sequence has been emitted
                    // for the observed notifications to flow into.
                    Tick();
                }

                var subscription = Params._source.Subscribe(this);

                if (recovery)
                {
                    SubscriptionInitializeVisitor.Subscribe(subscription);
                    SubscriptionInitializeVisitor.SetContext(subscription, Context);
                }
                else
                {
                    SubscriptionInitializeVisitor.Initialize(subscription, Context);
                }

                _subscription.Subscription = subscription;
            }
Ejemplo n.º 3
0
        public void Where_DisposeInPredicate()
        {
            var invoked = 0;

            var xs = Scheduler.CreateHotObservable(
                OnNext(110, 1),
                OnNext(180, 2),
                OnNext(230, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(380, 6),
                OnNext(390, 7),
                OnNext(450, 8),
                OnNext(470, 9),
                OnNext(560, 10),
                OnNext(580, 11),
                OnCompleted <int>(600),
                OnNext(610, 12),
                OnError <int>(620, new Exception()),
                OnCompleted <int>(630)
                );

            var res = Scheduler.CreateObserver <int>();

            var d  = default(ISubscription);
            var ys = default(ISubscribable <int>);

            Scheduler.ScheduleAbsolute(Created, () => ys = xs.Where(x =>
            {
                invoked++;
                if (x == 8)
                {
                    d.Dispose();
                }
                return(IsPrime(x));
            }));

            Scheduler.ScheduleAbsolute(Subscribed, () =>
            {
                d = ys.Subscribe(res);
                SubscriptionInitializeVisitor.Initialize(d, Scheduler.CreateContext());
            });

            Scheduler.ScheduleAbsolute(Disposed, () => d.Dispose());

            Scheduler.Start();

            res.Messages.AssertEqual(
                OnNext(230, 3),
                OnNext(340, 5),
                OnNext(390, 7)
                );

            xs.Subscriptions.AssertEqual(
                Subscribe(200, 450));

            Assert.AreEqual(6, invoked);
        }
Ejemplo n.º 4
0
        public void SelectWithIndex_DisposeInsideSelector()
        {
            var xs = Scheduler.CreateHotObservable(
                OnNext(100, 4),
                OnNext(200, 3),
                OnNext(500, 2),
                OnNext(600, 1)
                );

            var invoked = 0;

            var res = Scheduler.CreateObserver <int>();

            var d = default(ISubscription);

            d = xs.Select((x, index) =>
            {
                invoked++;
                if (Scheduler.Clock > 400)
                {
                    d.Dispose();
                }
                return(x + index * 10);
            }).Subscribe(res);

            SubscriptionInitializeVisitor.Initialize(d, Scheduler.CreateContext());

            Scheduler.ScheduleAbsolute(Disposed, d.Dispose);

            Scheduler.Start();

            res.Messages.AssertEqual(
                OnNext(100, 4),
                OnNext(200, 13)
                );

            xs.Subscriptions.AssertEqual(
                Subscribe(0, 500));

            Assert.AreEqual(3, invoked);
        }
Ejemplo n.º 5
0
            public void OnError(Exception error)
            {
                if (_retryCount <= 1)
                {
                    Output.OnError(error);
                    Dispose();
                }
                else
                {
                    _retryCount--;
                    StateChanged = true;

                    _context.TraceSource.Retry_Retrying_Count(_context.InstanceId, _retryCount, error);

                    var subscription = default(ISubscription);
                    try
                    {
                        subscription = Params._source.Subscribe(this);
                        _subscription.Subscription = subscription;

                        SubscriptionInitializeVisitor.Initialize(subscription, _context);
                        _context.TraceSource.Retry_Retrying(_context.InstanceId, error);
                    }
                    catch (Exception ex)
                    {
                        if (subscription != null)
                        {
                            subscription.Dispose();
                        }

                        Output.OnError(ex);
                        Dispose();
                        return;
                    }
                }
            }
Ejemplo n.º 6
0
        private void InitializeSubscription(ISubscription subscription)
        {
            var visitor = new SubscriptionInitializeVisitor(subscription);

            visitor.Initialize(_logicalContext);
        }