public void InnerNext(InnerObserver <R> sender, R item)
            {
                if (Interlocked.CompareExchange(ref wip, 1, 0) == 0)
                {
                    var q = sender.GetQueue();

                    if (current == sender && (q == null || q.IsEmpty()))
                    {
                        downstream.OnNext(item);
                    }
                    else
                    {
                        if (q == null)
                        {
                            q = sender.CreateQueue(capacityHint);
                        }
                        q.Offer(item);
                    }
                    if (Interlocked.Decrement(ref wip) == 0)
                    {
                        return;
                    }
                }
                else
                {
                    var q = sender.GetOrCreateQueue(capacityHint);
                    q.Offer(item);
                    if (Interlocked.Increment(ref wip) != 1)
                    {
                        return;
                    }
                }

                DrainLoop();
            }
 public void InnerNext(InnerObserver <R> sender, R item)
 {
     if (Interlocked.CompareExchange(ref wip, 1, 0) == 0)
     {
         var a = Volatile.Read(ref active);
         if (a == sender)
         {
             downstream.OnNext(item);
         }
         if (Interlocked.Decrement(ref wip) == 0)
         {
             return;
         }
     }
     else
     {
         var a = Volatile.Read(ref active);
         if (a == sender)
         {
             var q = sender.GetOrCreateQueue(capacityHint);
             q.Offer(item);
             if (Interlocked.Increment(ref wip) != 1)
             {
                 return;
             }
         }
     }
     DrainLoop();
 }
            void InnerError(InnerObserver sender, Exception ex)
            {
                var c = Volatile.Read(ref current);
                if (c == sender)
                {
                    if (Interlocked.CompareExchange(ref current, null, c) == c)
                    {
                        if (delayErrors)
                        {
                            ExceptionHelper.AddException(ref errors, ex);
                            if (done && Volatile.Read(ref current) == null)
                            {
                                Terminate();
                            }
                        }
                        else
                        {
                            if (Interlocked.CompareExchange(ref errors, ex, null) == null)
                            {
                                Interlocked.Exchange(ref current, DISPOSED)?.Dispose();
                                Terminate();
                            }
                        }

                    }
                }
            }
Ejemplo n.º 4
0
            internal override void InnerSuccess(InnerObserver sender, T item)
            {
                Remove(sender);
                if (Volatile.Read(ref wip) == 0 && Interlocked.CompareExchange(ref wip, 1, 0) == 0)
                {
                    downstream.OnNext(item);
                    if (Interlocked.Decrement(ref active) != 0)
                    {
                        if (Interlocked.Decrement(ref wip) == 0)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    var q = GetOrCreateQueue();
                    q.Enqueue(item);

                    Interlocked.Decrement(ref active);
                    if (Interlocked.Increment(ref wip) != 1)
                    {
                        return;
                    }
                }

                DrainLoop();
            }
            public override void OnNext(T value)
            {
                if (done)
                {
                    return;
                }

                var c = default(ICompletableSource);

                try
                {
                    c = RequireNonNullRef(mapper(value), "The mapper returned a null ICompletableSource");
                }
                catch (Exception ex)
                {
                    OnError(ex);
                    DisposableHelper.Dispose(ref upstream);
                    return;
                }

                var inner = new InnerObserver(this);

                if (Add(inner))
                {
                    Interlocked.Increment(ref active);
                    c.Subscribe(inner);
                }
            }
Ejemplo n.º 6
0
 internal override void InnerError(InnerObserver sender, Exception ex)
 {
     Remove(sender);
     InnerError(ex);
     Interlocked.Decrement(ref active);
     Drain();
 }
 void Signal(InnerObserver sender, T item)
 {
     Remove(sender);
     queue.Enqueue(item);
     Interlocked.Decrement(ref active);
     Drain();
 }
            public void UpstreamNext(T value)
            {
                if (IsDisposed())
                {
                    return;
                }
                var o = default(IObservable <R>);

                try
                {
                    o = mapper(value);
                }
                catch (Exception ex)
                {
                    base.Dispose();
                    OnError(ex);
                    return;
                }

                var inner = new InnerObserver <R>(this);

                observers.Offer(inner);

                if (!IsDisposed())
                {
                    inner.OnSubscribe(o.Subscribe(inner));
                }
                Drain();
            }
 public ConcatMapObserver(ICompletableObserver downstream, Func <T, ICompletableSource> mapper, bool delayErrors)
 {
     this.downstream  = downstream;
     this.mapper      = mapper;
     this.delayErrors = delayErrors;
     this.inner       = new InnerObserver(this);
     this.queue       = new ConcurrentQueue <T>();
 }
 public ConcatMapMainObserver(ISignalObserver<R> downstream, Func<T, IObservableSource<R>> mapper, bool delayErrors, int capacityHint)
 {
     this.downstream = downstream;
     this.mapper = mapper;
     this.delayErrors = delayErrors;
     this.capacityHint = capacityHint;
     this.inner = new InnerObserver(downstream, this);
 }
Ejemplo n.º 11
0
 public ConcatMapObserver(IObserver <R> downstream, Func <T, IMaybeSource <R> > mapper, bool delayErrors)
 {
     this.downstream  = downstream;
     this.mapper      = mapper;
     this.delayErrors = delayErrors;
     this.queue       = new ConcurrentQueue <T>();
     this.inner       = new InnerObserver(this);
 }
Ejemplo n.º 12
0
 protected override void InnerComplete(InnerObserver sender)
 {
     Remove(sender);
     if (Interlocked.Decrement(ref active) == 0)
     {
         Drain();
     }
 }
Ejemplo n.º 13
0
 public void InnerComplete(InnerObserver <R> sender)
 {
     sender.Dispose();
     if (Volatile.Read(ref active) == sender)
     {
         sender.SetDone();
         Drain();
     }
 }
 public void InnerError(InnerObserver <R> sender, Exception error)
 {
     if (Interlocked.CompareExchange(ref this.error, error, null) == null)
     {
         sender.SetDone();
         Volatile.Write(ref done, true);
         Drain();
     }
 }
Ejemplo n.º 15
0
            protected void UpstreamNext(IObservable <T> value)
            {
                Interlocked.Increment(ref active);
                var inner = new InnerObserver(this);

                if (Add(inner))
                {
                    inner.OnSubscribe(value.Subscribe(inner));
                }
            }
 public ObservableSourceAmbCoordinator(ISignalObserver <T> downstream, int n)
 {
     this.downstream = downstream;
     this.observers  = new InnerObserver[n];
     for (int i = 0; i < n; i++)
     {
         observers[i] = new InnerObserver(downstream, this, i);
     }
     Volatile.Write(ref winner, -1);
 }
        internal bool SubscribeTo(ISingleSource <T> source)
        {
            var inner = new InnerObserver(this);

            if (Add(inner))
            {
                source.Subscribe(inner);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 18
0
        internal bool SubscribeTo(IObservableSource <T> source)
        {
            var inner = new InnerObserver(this);

            if (Add(inner))
            {
                Interlocked.Increment(ref active);
                source.Subscribe(inner);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 19
0
        public MaybeAmbCoordinator(IMaybeObserver <T> downstream, int n)
        {
            this.downstream = downstream;
            var o = new InnerObserver[n];

            for (int i = 0; i < n; i++)
            {
                o[i] = new InnerObserver(this, i);
            }
            this.observers = o;
            Volatile.Write(ref winner, -1);
        }
Ejemplo n.º 20
0
 void InnerError(InnerObserver sender, Exception error)
 {
     if (delayErrors)
     {
         ExceptionHelper.AddException(ref errors, error);
         sender.SetDone();
     }
     else
     {
         Interlocked.CompareExchange(ref errors, error, null);
     }
     Drain();
 }
Ejemplo n.º 21
0
            public override void OnNext(T value)
            {
                var o = observers;
                var n = o.Length;

                var otherValues = new U[n];

                var found = true;

                for (int i = 0; i < n; i++)
                {
                    InnerObserver inner = Volatile.Read(ref o[i]);
                    if (inner == null)
                    {
                        return;
                    }
                    if (!inner.TryLatest(out otherValues[i]))
                    {
                        found = false;
                        break;
                    }
                }

                if (found)
                {
                    var result = default(R);

                    try
                    {
                        result = mapper(value, otherValues);
                    }
                    catch (Exception ex)
                    {
                        OnError(ex);
                        base.Dispose();
                        return;
                    }

                    if (Interlocked.CompareExchange(ref wip, 1, 0) == 0)
                    {
                        downstream.OnNext(result);
                        if (Interlocked.Decrement(ref wip) != 0)
                        {
                            var ex = ExceptionHelper.Terminate(ref errors);
                            downstream.OnError(ex);
                            base.Dispose();
                        }
                    }
                }
            }
Ejemplo n.º 22
0
 void InnerError(InnerObserver sender, Exception ex)
 {
     Remove(sender);
     if (delayErrors)
     {
         ExceptionHelper.AddException(ref errors, ex);
     }
     else
     {
         Interlocked.CompareExchange(ref errors, ex, null);
     }
     Interlocked.Decrement(ref active);
     Drain();
 }
 void InnerCompleted(InnerObserver sender)
 {
     var c = Volatile.Read(ref current);
     if (c == sender)
     {
         if (Interlocked.CompareExchange(ref current, null, c) == c)
         {
             if (done && Volatile.Read(ref current) == null)
             {
                 Terminate();
             }
         }
     }
 }
 void SignalError(InnerObserver sender, Exception ex)
 {
     Remove(sender);
     if (delayErrors)
     {
         ExceptionHelper.AddException(ref errors, ex);
         Interlocked.Decrement(ref active);
     }
     else
     {
         upstream.Dispose();
         Interlocked.CompareExchange(ref errors, ex, null);
     }
     Drain();
 }
Ejemplo n.º 25
0
 protected void Remove(InnerObserver inner)
 {
     if (Volatile.Read(ref disposed))
     {
         return;
     }
     lock (this)
     {
         if (Volatile.Read(ref disposed))
         {
             return;
         }
         disposables.Remove(inner);
     }
 }
Ejemplo n.º 26
0
 protected bool Add(InnerObserver inner)
 {
     if (!Volatile.Read(ref disposed))
     {
         lock (this)
         {
             if (!Volatile.Read(ref disposed))
             {
                 disposables.Add(inner);
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 27
0
            public ZipCoordinator(IObserver <R> downstream, Func <T[], R> mapper, bool delayErrors, int n)
            {
                this.downstream  = downstream;
                this.mapper      = mapper;
                this.delayErrors = delayErrors;
                var o = new InnerObserver[n];

                for (int i = 0; i < n; i++)
                {
                    o[i] = new InnerObserver(this);
                }
                this.observers = o;
                this.values    = new T[n];
                this.hasValues = new bool[n];
            }
Ejemplo n.º 28
0
            internal CombineCoordinator(IObserver <R> downstream, Func <T[], R> mapper, bool delayErrors, int n)
            {
                this.downstream  = downstream;
                this.mapper      = mapper;
                this.delayErrors = delayErrors;
                this.hasLatest   = new bool[n];
                var o = new InnerObserver[n];

                for (int i = 0; i < n; i++)
                {
                    o[i] = new InnerObserver(this, i);
                }
                this.observers = o;
                this.values    = new T[n];
                this.queue     = new ConcurrentQueue <Signal>();
            }
        internal void Remove(InnerObserver inner)
        {
            if (IsDisposed())
            {
                return;
            }

            lock (this)
            {
                if (IsDisposed())
                {
                    return;
                }
                observers.Remove(inner);
            }
        }
Ejemplo n.º 30
0
        internal MaybeZipCoordinator(IMaybeObserver <R> downstream, int n, Func <T[], R> mapper, bool delayErrors)
        {
            this.downstream = downstream;
            var o = new InnerObserver[n];

            for (int i = 0; i < n; i++)
            {
                o[i] = new InnerObserver(this, i);
            }

            this.observers   = o;
            this.mapper      = mapper;
            this.values      = new T[n];
            this.delayErrors = delayErrors;
            Volatile.Write(ref ready, n);
        }