示例#1
0
            public void OnNext(ISubscribable <TSource> source)
            {
                var id = default(ulong);

                lock (_lock)
                {
                    id         = unchecked (++_latest);
                    _hasLatest = true;
                }

                try
                {
                    var observer = new i(this, id);

                    var subscription = SubscribeInner <TSource>(source, observer);
                    observer.Subscription = subscription;

                    SubscriptionInitializeVisitor.Subscribe(subscription);
                    SubscriptionInitializeVisitor.SetContext(subscription, _context);

                    _innerSubscription.Subscription = subscription;

                    SubscriptionInitializeVisitor.Start(subscription);
                }
                catch (Exception ex)
                {
                    lock (_lock)
                    {
                        Output.OnError(ex);
                        Dispose();
                    }
                }
            }
示例#2
0
            public void OnNext(TSource value)
            {
                var throttle = default(ISubscribable <TThrottle>);

                try
                {
                    throttle = Params._throttleSelector(value);
                }
                catch (Exception error)
                {
                    lock (_gate)
                    {
                        Output.OnError(error);
                        Dispose();
                    }

                    return;
                }

                ulong currentId;

                lock (_gate)
                {
                    _hasValue = true;
                    _value    = value;
                    _id       = unchecked (_id + 1);
                    currentId = _id;
                }

                try
                {
#pragma warning disable IDE0079 // Remove unnecessary suppression.
#pragma warning disable CA2000  // Dispose objects before losing scope. (Observer will be owned by inner subscription.)

                    var observer = new ThrottleObserver(this, value, currentId);

                    var subscription = SubscribeInner <TThrottle>(throttle, observer);
                    observer.Subscription = subscription;

                    SubscriptionInitializeVisitor.Subscribe(subscription);
                    SubscriptionInitializeVisitor.SetContext(subscription, _context);

                    _cancelable.Subscription = subscription;

                    SubscriptionInitializeVisitor.Start(subscription);

#pragma warning restore CA2000
#pragma warning restore IDE0079
                }
                catch (Exception error)
                {
                    lock (_gate)
                    {
                        Output.OnError(error);
                        Dispose();
                    }
                }
            }
示例#3
0
            public void OnNext(TSource value)
            {
                lock (_lock)
                {
                    if (_innerSubscriptions.Count >= _maxInnerCount)
                    {
                        Output.OnError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The number of concurrent nested sequences produced by the SelectMany operator exceeded {0} items. Please review the SelectMany operator usage to avoid exceeding this limit.", _maxInnerCount)));
                        Dispose();

                        return;
                    }
                }

                ISubscribable <TCollection> collection;

                try
                {
                    collection = Params._collectionSelector(value);

#pragma warning disable IDE0079 // Remove unnecessary suppression.
#pragma warning disable CA2000  // Dispose objects before losing scope. (Observer will be owned by inner subscription.)

                    var observer = new Observer(this, value);

                    var subscription = SubscribeInner <TCollection>(collection, observer);
                    observer.Subscription = subscription;

                    SubscriptionInitializeVisitor.Subscribe(subscription);
                    SubscriptionInitializeVisitor.SetContext(subscription, _context);

                    lock (_lock)
                    {
                        // No need to set dirty flag here, the SubscribeInner call returns
                        // an operator with the dirty flag set to true.
                        _innerSubscriptions.Add(subscription);
                    }

                    SubscriptionInitializeVisitor.Start(subscription);

#pragma warning restore CA2000
#pragma warning restore IDE0079
                }
                catch (Exception ex)
                {
                    lock (_lock)
                    {
                        Output.OnError(ex);
                        Dispose();
                        return;
                    }
                }
            }
示例#4
0
        public void SubscriptionStateVisitor_Basics()
        {
            var state         = new MockOperatorStateContainer();
            var writerFactory = state.CreateWriter();
            var readerFactory = state.CreateReader();

            var xs = new SimpleSubject <int>();
            var o  = xs.CreateObserver();

            var ys = new Take <int>(xs, 5);

            {
                var s1 = ys.Subscribe(Observer.Create <int>(_ => { }, _ => { }, () => { }));
                var v  = new SubscriptionInitializeVisitor(s1);
                v.Subscribe();
                v.Start();

                o.OnNext(42);
                o.OnNext(43);

                var sv = new SubscriptionStateVisitor(s1);

                Assert.IsTrue(sv.HasStateChanged());

                sv.SaveState(writerFactory);

                Assert.IsTrue(sv.HasStateChanged());

                sv.OnStateSaved();

                Assert.IsFalse(sv.HasStateChanged());

                o.OnNext(44);
                o.OnNext(45);

                Assert.IsTrue(sv.HasStateChanged());
            }

            {
                var done = false;

                var s2 = ys.Subscribe(Observer.Create <int>(_ => { }, _ => { }, () => { done = true; }));

                var sv = new SubscriptionStateVisitor(s2);

                sv.LoadState(readerFactory);

                var v = new SubscriptionInitializeVisitor(s2);
                v.Subscribe();
                v.Start();

                o.OnNext(46);
                Assert.IsFalse(done);

                o.OnNext(47);
                Assert.IsFalse(done);

                o.OnNext(48);
                Assert.IsTrue(done);
            }
        }
示例#5
0
        protected override void StartCore(ISubscription instance, params object[] args)
        {
            Debug.Assert(args.Length == 0);

            SubscriptionInitializeVisitor.Start(instance);
        }