public TimeoutObserver(ISignalObserver <T> downstream, TimeSpan timeout, IScheduler scheduler, IObservableSource <T> fallback)
 {
     this.downstream = downstream;
     this.timeout    = timeout;
     this.scheduler  = scheduler;
     this.fallback   = fallback;
 }
 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)>();
 }
            IDisposable Timeout(long idx)
            {
                if (Volatile.Read(ref index) == idx && Interlocked.CompareExchange(ref index, long.MaxValue, idx) == idx)
                {
                    DisposableHelper.Dispose(ref upstream);

                    var src = fallback;
                    fallback = null;

                    if (src != null)
                    {
                        var fo = new FallbackObserver(downstream);

                        if (DisposableHelper.Replace(ref other, fo))
                        {
                            src.Subscribe(fo);
                        }
                    }
                    else
                    {
                        downstream.OnError(new TimeoutException($"Timeout at index " + idx));
                    }
                }

                return(DisposableHelper.EMPTY);
            }
示例#4
0
 internal ObservableSourceMergeMany(IObservableSource <IObservableSource <T> > source, bool delayErrors, int maxConcurrency, int capacityHint)
 {
     this.source         = source;
     this.delayErrors    = delayErrors;
     this.maxConcurrency = maxConcurrency;
     this.capacityHint   = capacityHint;
 }
示例#5
0
 internal static IObservableSource <T> Create(
     IObservableSource <T> source,
     Action <T> onNext                = null,
     Action <T> onAfterNext           = null,
     Action <Exception> onError       = null,
     Action onCompleted               = null,
     Action onTerminate               = null,
     Action onAfterTerminate          = null,
     Action doFinally                 = null,
     Action <IDisposable> onSubscribe = null,
     Action onDispose                 = null
     )
 {
     if (source is ObservableSourcePeek <T> p)
     {
         return(new ObservableSourcePeek <T>(p.source,
                                             Combine(p.onNext, onNext),
                                             Combine(p.onAfterNext, onAfterNext),
                                             Combine(p.onError, onError),
                                             Combine(p.onCompleted, onCompleted),
                                             Combine(p.onTerminate, onTerminate),
                                             Combine(p.onAfterTerminate, onAfterTerminate),
                                             Combine(p.doFinally, doFinally),
                                             Combine(p.onSubscribe, onSubscribe),
                                             Combine(p.onDispose, onDispose)
                                             ));
     }
     return(new ObservableSourcePeek <T>(source,
                                         onNext, onAfterNext, onError, onCompleted,
                                         onTerminate, onAfterTerminate, doFinally,
                                         onSubscribe, onDispose
                                         ));
 }
示例#6
0
        public void Basic()
        {
            IObservableSource <int> source = Observable.Range(1, 5).ToObservableSource();

            source.Test()
            .AssertResult(1, 2, 3, 4, 5);
        }
示例#7
0
 public ObservableSourceGroupBy(IObservableSource <T> source, Func <T, K> keySelector, Func <T, V> valueSelector, IEqualityComparer <K> keyComparer)
 {
     this.source        = source;
     this.keySelector   = keySelector;
     this.valueSelector = valueSelector;
     this.keyComparer   = keyComparer;
 }
            internal void Subscribe(IObservableSource <T> source)
            {
                if (Interlocked.Increment(ref wip) == 1)
                {
                    for (; ;)
                    {
                        if (!DisposableHelper.IsDisposed(ref upstream))
                        {
                            if (source == null)
                            {
                                var o = other;
                                other = null;

                                o.Subscribe(this);
                            }
                            else
                            {
                                var o = source;
                                source = null;

                                o.Subscribe(this);
                            }
                        }
                        if (Interlocked.Decrement(ref wip) == 0)
                        {
                            break;
                        }
                    }
                }
            }
 public ObservableSourceTimeout(IObservableSource <T> source, TimeSpan timeout, IScheduler scheduler, IObservableSource <T> fallback)
 {
     this.source    = source;
     this.timeout   = timeout;
     this.scheduler = scheduler;
     this.fallback  = fallback;
 }
示例#10
0
 public ObservableSourceBuffer(IObservableSource <T> source, Func <B> bufferSupplier, int size, int skip)
 {
     this.source         = source;
     this.bufferSupplier = bufferSupplier;
     this.size           = size;
     this.skip           = skip;
 }
 public ObservableSourceConcatMap(IObservableSource<T> source, Func<T, IObservableSource<R>> mapper, bool delayErrors, int capacityHint)
 {
     this.source = source;
     this.mapper = mapper;
     this.delayErrors = delayErrors;
     this.capacityHint = capacityHint;
 }
 public ObservableSourceDelay(IObservableSource <T> source, TimeSpan delay, IScheduler scheduler, bool delayError)
 {
     this.source     = source;
     this.delay      = delay;
     this.scheduler  = scheduler;
     this.delayError = delayError;
 }
 public ObservableSourceObserveOn(IObservableSource <T> source, IScheduler scheduler, bool delayError, int capacityHint, bool fair)
 {
     this.source       = source;
     this.scheduler    = scheduler;
     this.delayError   = delayError;
     this.capacityHint = capacityHint;
     this.fair         = fair;
 }
 public WindowBoundaryMainObserver(ISignalObserver <IObservableSource <T> > downstream)
 {
     this.downstream  = downstream;
     this.queue       = new ConcurrentQueue <(T item, bool boundary, bool done)>();
     this.boundary    = new BoundaryObserver(this);
     this.onTerminate = TerminateWindow;
     Volatile.Write(ref active, 1);
 }
 public ObservableSourceJoin(IObservableSource <TLeft> left, IObservableSource <TRight> right, Func <TLeft, IObservableSource <TLeftEnd> > leftSelector, Func <TRight, IObservableSource <TRightEnd> > rightSelector, Func <TLeft, TRight, TResult> resultSelector)
 {
     this.left           = left;
     this.right          = right;
     this.leftSelector   = leftSelector;
     this.rightSelector  = rightSelector;
     this.resultSelector = resultSelector;
 }
示例#16
0
 public ObservableSourceWithLatestFrom(IObservableSource <T> source, IObservableSource <U>[] others, Func <T, U[], R> mapper, bool delayErrors, bool sourceFirst)
 {
     this.source      = source;
     this.others      = others;
     this.mapper      = mapper;
     this.delayErrors = delayErrors;
     this.sourceFirst = sourceFirst;
 }
示例#17
0
        public void Error()
        {
            IObservableSource <int> source = Observable.Throw <int>(new InvalidOperationException())
                                             .ToObservableSource();

            source.Test()
            .AssertFailure(typeof(InvalidOperationException));
        }
示例#18
0
        public ObservableSourceCache(IObservableSource <T> source, Action <IDisposable> cancel, int capacityHint)
        {
            this.source = source;
            this.cancel = cancel;
            var n = new Node(capacityHint);

            this.tail = n;
            this.head = n;
            Volatile.Write(ref this.observers, EMPTY);
        }
示例#19
0
            protected void UpstreamNext(IObservableSource <T> value)
            {
                Interlocked.Increment(ref active);
                var inner = new InnerObserver(this);

                if (Add(inner))
                {
                    value.Subscribe(inner);
                }
            }
 internal ObservableSourceConcatMapEager(
     IObservableSource <T> source,
     Func <T, IObservableSource <R> > mapper,
     int maxConcurrency,
     int capacityHint)
 {
     this.source         = source;
     this.mapper         = mapper;
     this.maxConcurrency = maxConcurrency;
     this.capacityHint   = capacityHint;
 }
                public void OnError(Exception ex)
                {
                    var p = Volatile.Read(ref parent);

                    if (p != null)
                    {
                        var src = source;
                        parent = null;
                        source = null;
                        p.OnError(ex);
                    }
                }
示例#22
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);
        }
                public void OnNext(U item)
                {
                    var p = Volatile.Read(ref parent);

                    if (p != null)
                    {
                        var src = source;
                        parent = null;
                        source = null;
                        DisposableHelper.Dispose(ref upstream);
                        src.Subscribe(p);
                    }
                }
                public void OnCompleted()
                {
                    var p = Volatile.Read(ref parent);

                    if (p != null)
                    {
                        var src = source;
                        parent = null;
                        source = null;
                        DisposableHelper.WeakDispose(ref upstream);
                        src.Subscribe(p);
                    }
                }
示例#25
0
        public static void AssertFuseableApi <T>(IObservableSource <T> source, bool boundary = false)
        {
            var parent = new FusionMethodCalls <T>(boundary);

            source.Subscribe(parent);

            var ex = parent.error;

            if (ex != null)
            {
                throw ex;
            }
        }
示例#26
0
 private ObservableSourcePeek(IObservableSource <T> source, Action <T> onNext, Action <T> onAfterNext, Action <Exception> onError, Action onCompleted, Action onTerminate, Action onAfterTerminate, Action doFinally, Action <IDisposable> onSubscribe, Action onDispose)
 {
     this.source           = source;
     this.onNext           = onNext;
     this.onAfterNext      = onAfterNext;
     this.onError          = onError;
     this.onCompleted      = onCompleted;
     this.onTerminate      = onTerminate;
     this.onAfterTerminate = onAfterTerminate;
     this.doFinally        = doFinally;
     this.onSubscribe      = onSubscribe;
     this.onDispose        = onDispose;
 }
示例#27
0
        public void Dispose()
        {
            var subj = new Subject <int>();

            IObservableSource <int> source = subj.ToObservableSource();

            var to = source.Test();

            Assert.True(subj.HasObservers);

            to.AssertEmpty();

            to.Dispose();

            Assert.False(subj.HasObservers);
        }
示例#28
0
            internal void Run(IObservableSource <T> first)
            {
                if (Interlocked.Increment(ref wip) != 1)
                {
                    return;
                }

                for (; ;)
                {
                    if (first != null)
                    {
                        first.Subscribe(this);
                        first = null;
                    }
                    else
                    {
                        var idx = index;
                        if (idx == fallbacks.Length)
                        {
                            downstream.OnCompleted();
                        }
                        else
                        {
                            var src = fallbacks[idx];
                            if (src == null)
                            {
                                downstream.OnError(new NullReferenceException("The fallbacks[" + idx + "] is null"));
                            }
                            else
                            {
                                index = idx + 1;
                                src.Subscribe(this);
                            }
                        }
                    }


                    if (Interlocked.Decrement(ref wip) == 0)
                    {
                        break;
                    }
                }
            }
示例#29
0
 public static IObservableSource <T> ConcatError <T>(this IObservableSource <T> source, Exception ex)
 {
     return(source.Concat(ObservableSource.Error <T>(ex)));
 }
示例#30
0
 public ObservableSourceReduce(IObservableSource <T> source, Func <C> initialSupplier, Func <C, T, C> reducer)
 {
     this.source          = source;
     this.initialSupplier = initialSupplier;
     this.reducer         = reducer;
 }