public void OnNext(T item)
            {
                if (done)
                {
                    return;
                }

                if (gate)
                {
                    downstream.OnNext(item);
                }
                else
                {
                    var b = false;
                    try
                    {
                        b = predicate(item);
                    }
                    catch (Exception ex)
                    {
                        upstream.Dispose();
                        OnError(ex);
                        return;
                    }

                    if (!b)
                    {
                        gate = true;
                        downstream.OnNext(item);
                    }
                }
            }
Exemplo n.º 2
0
 public void OnCompleted()
 {
     if (Volatile.Read(ref state) == StateFused)
     {
         Volatile.Write(ref state, StateReady);
         downstream.OnNext(default(T));
         if (!Volatile.Read(ref disposed))
         {
             downstream.OnCompleted();
         }
     }
     else
     {
         var queue = this.queue;
         while (queue.Count != 0)
         {
             if (Volatile.Read(ref disposed))
             {
                 return;
             }
             downstream.OnNext(queue.Dequeue());
         }
         if (Volatile.Read(ref disposed))
         {
             return;
         }
         downstream.OnCompleted();
     }
 }
 public void OnNext(T item)
 {
     if (won)
     {
         downstream.OnNext(item);
     }
     else
     if (parent.TryWin(index))
     {
         won = true;
         downstream.OnNext(item);
     }
 }
Exemplo n.º 4
0
            public void OnNext(T item)
            {
                if (done)
                {
                    return;
                }
                downstream.OnNext(item);

                var b = false;

                try
                {
                    b = predicate(item);
                }
                catch (Exception ex)
                {
                    upstream.Dispose();
                    OnError(ex);
                    return;
                }

                if (b)
                {
                    upstream.Dispose();
                    OnCompleted();
                }
            }
Exemplo n.º 5
0
 internal static void Emit <T>(this ISignalObserver <T> subject, params T[] items)
 {
     foreach (var t in items)
     {
         subject.OnNext(t);
     }
 }
Exemplo n.º 6
0
            public void OnNext(T item)
            {
                if (done)
                {
                    return;
                }

                try
                {
                    onNext?.Invoke(item);
                }
                catch (Exception ex)
                {
                    Dispose();
                    OnError(ex);
                    return;
                }

                downstream.OnNext(item);

                try
                {
                    onAfterNext?.Invoke(item);
                }
                catch (Exception ex)
                {
                    Dispose();
                    OnError(ex);
                    return;
                }
            }
Exemplo n.º 7
0
            public void OnCompleted()
            {
                if (done)
                {
                    return;
                }
                var b = buffer;

                buffer = default;

                if (b != null)
                {
                    downstream.OnNext(b);
                }
                downstream.OnCompleted();
            }
Exemplo n.º 8
0
            public void OnNext(T item)
            {
                var idx = index;
                var w   = window;

                if (index == 0 && Volatile.Read(ref once) == 0)
                {
                    w      = new MonocastSubject <T>(size, onTerminate);
                    window = w;
                    Interlocked.Increment(ref active);
                    downstream.OnNext(w);
                }

                w?.OnNext(item);

                if (++idx == size)
                {
                    w?.OnCompleted();
                    window = null;
                    index  = 0;
                }
                else
                {
                    index = idx;
                }
            }
Exemplo n.º 9
0
 public void OnNext(T item)
 {
     if (upstream != DisposableHelper.DISPOSED)
     {
         downstream.OnNext(item);
     }
 }
            internal void Run()
            {
                if (DisposableHelper.IsDisposed(ref task))
                {
                    return;
                }
                if (fused)
                {
                    var fr = fusedReady;
                    if (fr == end)
                    {
                        downstream.OnCompleted();
                        Dispose();
                    }
                    else
                    {
                        Volatile.Write(ref fusedReady, fr + 1);
                        downstream.OnNext(default(long));

                        if (fr + 1 == end)
                        {
                            downstream.OnCompleted();
                            Dispose();
                        }
                    }
                }
                else
                {
                    var idx = index;
                    if (idx == end)
                    {
                        downstream.OnCompleted();
                        Dispose();
                    }
                    else
                    {
                        index = idx + 1;
                        downstream.OnNext(idx);
                        if (idx + 1 == end)
                        {
                            downstream.OnCompleted();
                            Dispose();
                        }
                    }
                }
            }
 public void OnNext(T item)
 {
     if (queue.Count == n)
     {
         downstream.OnNext(queue.Dequeue());
     }
     queue.Enqueue(item);
 }
            public void OnNext(T value)
            {
                var d = Volatile.Read(ref resource);

                if (d != DisposableHelper.DISPOSED)
                {
                    downstream.OnNext(value);
                }
            }
Exemplo n.º 13
0
            public void OnCompleted()
            {
                if (done)
                {
                    return;
                }

                var buffers = this.buffers;

                while (buffers.Count != 0)
                {
                    if (Volatile.Read(ref disposed))
                    {
                        buffers.Clear();
                        return;
                    }
                    downstream.OnNext(buffers.Dequeue());
                }
                downstream.OnCompleted();
            }
Exemplo n.º 14
0
 internal void Run()
 {
     if (Volatile.Read(ref state) == ModeFresh)
     {
         downstream.OnNext(item);
         if (Volatile.Read(ref state) == 0)
         {
             Volatile.Write(ref state, ModeDone);
             downstream.OnCompleted();
         }
     }
 }
        public void Complete(T result)
        {
            var s = Volatile.Read(ref state);

            if (s == Empty)
            {
                downstream.OnNext(result);
                if (Volatile.Read(ref state) != Disposed)
                {
                    downstream.OnCompleted();
                }
            }
            else
            if (s == FusedEmpty)
            {
                value = result;
                Volatile.Write(ref state, FusedReady);
                downstream.OnNext(default(T));
                downstream.OnCompleted();
            }
        }
Exemplo n.º 16
0
 public void InnerNext(InnerSignalObserver <R> sender, R item)
 {
     if (Interlocked.CompareExchange(ref wip, 1, 0) == 0)
     {
         downstream.OnNext(item);
         if (Interlocked.Decrement(ref wip) == 0)
         {
             return;
         }
     }
     else
     {
         var q = sender.GetOrCreateQueue(capacityHint);
         q.TryOffer(item);
         if (Interlocked.Increment(ref wip) != 1)
         {
             return;
         }
     }
     DrainLoop();
 }
Exemplo n.º 17
0
            internal void Run()
            {
                var s = Volatile.Read(ref state);

                if (s == Empty)
                {
                    downstream.OnNext(0L);
                    if (Volatile.Read(ref state) != Disposed)
                    {
                        Volatile.Write(ref state, Disposed);
                        downstream.OnCompleted();
                    }
                }
                else
                if (s == FusedEmpty)
                {
                    Volatile.Write(ref state, FusedReady);
                    downstream.OnNext(default(long));
                    downstream.OnCompleted();
                }
            }
            public void OnNext(T item)
            {
                var r = remaining;

                if (r == 0)
                {
                    downstream.OnNext(item);
                }
                else
                {
                    remaining = r - 1;
                }
            }
 public void OnNext(T value)
 {
     if (Interlocked.CompareExchange(ref wip, 1, 0) == 0)
     {
         if (!terminated)
         {
             downstream.OnNext(value);
             if (Interlocked.Decrement(ref wip) == 0)
             {
                 return;
             }
         }
     }
     else
     {
         var q = GetOrCreateQueue();
         q.Enqueue(value);
         if (Interlocked.Increment(ref wip) != 1)
         {
             return;
         }
     }
     DrainLoop();
 }
Exemplo n.º 20
0
            public void OnNext(T item)
            {
                long r = remaining;

                if (r > 0)
                {
                    remaining = --r;
                    downstream.OnNext(item);

                    if (r == 0L)
                    {
                        upstream.Dispose();
                        downstream.OnCompleted();
                    }
                }
            }
            internal void Run()
            {
                if (fused)
                {
                    return;
                }

                for (; ;)
                {
                    if (Volatile.Read(ref disposed))
                    {
                        enumerator?.Dispose();
                        enumerator = null;
                        break;
                    }
                    else
                    {
                        var v   = default(T);
                        var has = false;

                        try
                        {
                            has = enumerator.MoveNext();
                            if (has)
                            {
                                v = enumerator.Current;
                            }
                        }
                        catch (Exception ex)
                        {
                            downstream.OnError(ex);
                            break;
                        }

                        if (has)
                        {
                            downstream.OnNext(v);
                        }
                        else
                        {
                            downstream.OnCompleted();
                            Volatile.Write(ref disposed, true);
                        }
                    }
                }
            }
Exemplo n.º 22
0
 public static void OnNext <T>(ISignalObserver <T> observer, T item, ref int wip, ref Exception error)
 {
     if (Interlocked.CompareExchange(ref wip, 1, 0) == 0)
     {
         observer.OnNext(item);
         if (Interlocked.Decrement(ref wip) != 0)
         {
             var ex = Volatile.Read(ref error);
             if (ex != ExceptionHelper.TERMINATED)
             {
                 observer.OnError(ex);
             }
             else
             {
                 observer.OnCompleted();
             }
         }
     }
 }
Exemplo n.º 23
0
            public void OnNext(T item)
            {
                var idx = index;

                if (idx == 0 && Volatile.Read(ref once) == 0)
                {
                    var w = new MonocastSubject <T>(size, onTerminate);
                    windows.Enqueue(w);
                    Interlocked.Increment(ref active);
                    downstream.OnNext(w);
                }

                foreach (var w in windows)
                {
                    w.OnNext(item);
                }

                int c = count + 1;

                if (c == size)
                {
                    windows.Dequeue().OnCompleted();
                    count = c - skip;
                }
                else
                {
                    count = c;
                }

                if (++idx == skip)
                {
                    index = 0;
                }
                else
                {
                    index = idx;
                }
            }
Exemplo n.º 24
0
 public void OnNext(T item)
 {
     hasValue = true;
     downstream.OnNext(item);
 }
 public void OnNext(T item)
 {
     downstream.OnNext(item);
 }
 protected override bool Next(T item)
 {
     observer.OnNext(item);
     return(true);
 }
 public void OnNext(T value)
 {
     downstream.OnNext(value);
 }