コード例 #1
0
 public WindowExactObserver(ISignalObserver <IObservableSource <T> > downstream, int size)
 {
     this.downstream  = downstream;
     this.size        = size;
     this.onTerminate = TerminateWindow;
     Volatile.Write(ref active, 1);
 }
コード例 #2
0
        /// <summary>
        /// Subscribes the first observer to this subject and
        /// starts replaying/relaying signals. All future
        /// observers receive an InvalidOperationException.
        /// </summary>
        /// <param name="observer">The observer to subscribe with.</param>
        public void Subscribe(ISignalObserver <T> observer)
        {
            ValidationHelper.RequireNonNullRef(observer, nameof(observer));

            if (Interlocked.CompareExchange(ref once, 1, 0) == 0)
            {
                var inner = new MonocastDisposable(observer, this);
                observer.OnSubscribe(inner);
                if (Interlocked.CompareExchange(ref this.observer, inner, null) == null)
                {
                    if (inner.IsDisposed())
                    {
                        this.observer = null;
                    }
                    else
                    {
                        Drain();
                    }
                }
            }
            else
            {
                DisposableHelper.Error(observer, new InvalidOperationException("MonocastSubject allows at most one observer"));
            }
        }
コード例 #3
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new RepeatPredicteObserver(observer, source, predicate);

            observer.OnSubscribe(parent);
            parent.Next();
        }
コード例 #4
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            ValidationHelper.RequireNonNull(observer, nameof(observer));

            var errorSignals = new PublishSubject <Exception>();
            var redo         = default(IObservableSource <U>);

            try
            {
                redo = ValidationHelper.RequireNonNullRef(handler(errorSignals), "The handler returned a null IObservableSource");
            }
            catch (Exception ex)
            {
                DisposableHelper.Error(observer, ex);
                return;
            }

            var parent = new MainObserver(observer, source, new SerializedSignalObserver <Exception>(errorSignals));

            observer.OnSubscribe(parent);

            redo.Subscribe(parent.handlerObserver);

            parent.HandlerNext();
        }
コード例 #5
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var connectionDisposable = default(SingleAssignmentDisposable);
            var taskDisposable       = default(IDisposable);

            lock (this)
            {
                var t = task;
                if (t != null)
                {
                    taskDisposable = t;
                    task           = null;
                }

                if (++count == minObservers)
                {
                    connectionDisposable = new SingleAssignmentDisposable();
                    connection           = connectionDisposable;
                }
            }

            if (taskDisposable != null)
            {
                taskDisposable.Dispose();
            }

            source.Subscribe(new RefCountObserver(observer, this));

            if (connectionDisposable != null)
            {
                source.Connect(d => connectionDisposable.Disposable = d);
            }
        }
コード例 #6
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new ArrayDisposable(observer, array);

            observer.OnSubscribe(parent);
            parent.Run();
        }
コード例 #7
0
 public BufferSkipObserver(ISignalObserver <B> downstream, Func <B> bufferSupplier, int size, int skip)
 {
     this.downstream     = downstream;
     this.bufferSupplier = bufferSupplier;
     this.size           = size;
     this.skip           = skip;
 }
コード例 #8
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new FromFuncDisposable(observer);

            observer.OnSubscribe(parent);

            if (parent.IsDisposed())
            {
                return;
            }

            var v = default(T);

            try
            {
                v = supplier();
            }
            catch (Exception ex)
            {
                if (!parent.IsDisposed())
                {
                    parent.Error(ex);
                }
                return;
            }

            parent.Complete(v);
        }
コード例 #9
0
 internal static void Emit <T>(this ISignalObserver <T> subject, params T[] items)
 {
     foreach (var t in items)
     {
         subject.OnNext(t);
     }
 }
コード例 #10
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            if (serialize)
            {
                var parent = new CreateDisposableSerializedEmitter(observer);

                observer.OnSubscribe(parent);
                try
                {
                    onSubscribe(parent);
                }
                catch (Exception ex)
                {
                    parent.OnError(ex);
                }
            }
            else
            {
                var parent = new CreateDisposableEmitter(observer);
                observer.OnSubscribe(parent);
                try
                {
                    onSubscribe(parent);
                }
                catch (Exception ex)
                {
                    parent.OnError(ex);
                }
            }
        }
コード例 #11
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new FromActionDisposable(observer);

            observer.OnSubscribe(parent);

            if (parent.IsDisposed())
            {
                return;
            }

            try
            {
                action();
            }
            catch (Exception ex)
            {
                if (!parent.IsDisposed())
                {
                    parent.Error(ex);
                }
                return;
            }

            parent.Complete();
        }
コード例 #12
0
 public BufferBoundaryObserver(ISignalObserver <B> downstream, Func <B> bufferSupplier)
 {
     this.downstream     = downstream;
     this.bufferSupplier = bufferSupplier;
     this.boundary       = new BoundaryObserver(this);
     this.queue          = new ConcurrentQueue <(T item, int state)>();
 }
コード例 #13
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new JustDisposable(observer, item);

            observer.OnSubscribe(parent);
            parent.Run();
        }
コード例 #14
0
        public void Subscribe(ISignalObserver <int> observer)
        {
            var parent = new RangeDisposable(observer, start, end);

            observer.OnSubscribe(parent);
            parent.Run();
        }
コード例 #15
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new ConcatWithObserver(observer, other);

            observer.OnSubscribe(parent);
            parent.Subscribe(source);
        }
コード例 #16
0
 public TakeLastTimedObserver(ISignalObserver <T> downstream, TimeSpan timespan, IStopwatch stopwatch)
 {
     this.downstream = downstream;
     this.timespan   = timespan;
     this.stopwatch  = stopwatch;
     Volatile.Write(ref queue, new Queue <(T item, TimeSpan time)>());
 }
コード例 #17
0
        public void Subscribe(ISignalObserver <long> observer)
        {
            var parent = new IntervalDisposable(observer, start, end);

            observer.OnSubscribe(parent);

            if (initialDelay == period)
            {
                var d = scheduler.SchedulePeriodic(parent, period, t =>
                {
                    t.Run();
                });

                parent.SetTask(d);
            }
            else
            {
                var d = scheduler.Schedule((parent, period), initialDelay, (sch, state) =>
                {
                    state.parent.Run();
                    return(sch.SchedulePeriodic(state.parent, state.period, t =>
                    {
                        t.Run();
                    }));
                });

                parent.SetTask(d);
            }
        }
コード例 #18
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new RetryPredicteObserver(observer, source, times);

            observer.OnSubscribe(parent);
            parent.Next();
        }
コード例 #19
0
 internal ConcatMapEagerObserver(ISignalObserver <R> downstream, Func <T, IObservableSource <R> > mapper,
                                 int capacityHint) : base(downstream)
 {
     this.mapper       = mapper;
     this.capacityHint = capacityHint;
     this.observers    = new SpscLinkedArrayQueue <InnerSignalObserver <R> >(capacityHint);
 }
コード例 #20
0
 public IntervalDisposable(ISignalObserver <long> downstream, long index, long end)
 {
     this.downstream = downstream;
     this.index      = index;
     this.fusedReady = index;
     this.end        = end;
 }
コード例 #21
0
        /// <summary>
        /// Subscribes the observer to this subject and
        /// relays the live items or replays the terminal
        /// event to it.
        /// </summary>
        /// <param name="observer">The observer to dispatch signals to.</param>
        public void Subscribe(ISignalObserver <T> observer)
        {
            ValidationHelper.RequireNonNullRef(observer, nameof(observer));

            var parent = new PublishDisposable(observer, this);

            observer.OnSubscribe(parent);
            if (Add(parent))
            {
                if (parent.IsDisposed())
                {
                    Remove(parent);
                }
            }
            else
            {
                var ex = error;

                if (ex != ExceptionHelper.TERMINATED)
                {
                    parent.OnError(ex);
                }
                else
                {
                    parent.OnCompleted();
                }
            }
        }
コード例 #22
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            if (maxConcurrency == int.MaxValue)
            {
                var parent = new MergeMaxCoordinator(observer, delayErrors);
                observer.OnSubscribe(parent);

                foreach (var source in sources)
                {
                    if (source == null)
                    {
                        parent.Error(new NullReferenceException());
                        return;
                    }
                    if (!parent.SubscribeTo(source))
                    {
                        return;
                    }
                }

                parent.SetDone();
            }
            else
            {
                var parent = new MergeLimitedCoordinator(observer, delayErrors, maxConcurrency, sources);
                observer.OnSubscribe(parent);

                parent.Drain();
            }
        }
コード例 #23
0
 public TimeoutObserver(ISignalObserver <T> downstream, TimeSpan timeout, IScheduler scheduler, IObservableSource <T> fallback)
 {
     this.downstream = downstream;
     this.timeout    = timeout;
     this.scheduler  = scheduler;
     this.fallback   = fallback;
 }
コード例 #24
0
 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);
 }
コード例 #25
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new FromObserver(observer);

            observer.OnSubscribe(parent);

            parent.OnSubscribe(source.Subscribe(parent));
        }
コード例 #26
0
 public GroupByObserver(ISignalObserver <IGroupedObservableSource <K, V> > downstream, Func <T, K> keySelector, Func <T, V> valueSelector, IEqualityComparer <K> keyComparer)
 {
     this.downstream    = downstream;
     this.keySelector   = keySelector;
     this.valueSelector = valueSelector;
     this.groups        = new ConcurrentDictionary <K, Group>(keyComparer);
     Volatile.Write(ref active, 1);
 }
コード例 #27
0
 public ObserveOnObserver(ISignalObserver <T> downstream, IScheduler scheduler, bool delayError, int capacityHint, bool fair)
 {
     this.downstream   = downstream;
     this.scheduler    = scheduler;
     this.delayError   = delayError;
     this.capacityHint = capacityHint;
     this.fair         = fair;
 }
コード例 #28
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new SwitchIfEmptyObserver(observer, fallbacks);

            observer.OnSubscribe(parent);

            parent.Run(source);
        }
コード例 #29
0
 public BufferOverlapObserver(ISignalObserver <B> downstream, Func <B> bufferSupplier, int size, int skip)
 {
     this.downstream     = downstream;
     this.bufferSupplier = bufferSupplier;
     this.size           = size;
     this.skip           = skip;
     this.buffers        = new Queue <B>();
 }
コード例 #30
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new MainObserver(observer, source);

            observer.OnSubscribe(parent);

            other.Subscribe(parent.other);
        }