Exemple #1
0
        public void OnNext(T t)
        {
            Volatile.Read(ref other)?.Dispose();

            long i = Interlocked.Increment(ref index);

            IPublisher <U> p;

            try
            {
                p = selector(t);
            }
            catch (Exception ex)
            {
                Cancel();
                actual.OnError(ex);
                return;
            }

            if (p == null)
            {
                Cancel();
                actual.OnError(new NullReferenceException("The selector returned a null Publisher"));
                return;
            }

            PublisherDebounceInner inner = new PublisherDebounceInner(t, i, this);

            if (DisposableHelper.Replace(ref other, inner))
            {
                p.Subscribe(inner);
            }
        }
Exemple #2
0
        public IDisposable Schedule(Action task, TimeSpan initialDelay, TimeSpan period, IWorkerServices worker = null)
        {
            if (Prepare())
            {
                var run = runner;

                var t = new InterruptibleAction(task, true);
                t.parent = worker;

                if (worker == null || worker.AddAction(t))
                {
                    var d = timed.Schedule(() =>
                    {
                        if (!t.IsDisposed)
                        {
                            run.Offer(t.Run);
                        }
                    }, initialDelay, period);
                    DisposableHelper.Replace(ref t.resource, d);

                    return(t);
                }
            }
            return(EmptyDisposable.Instance);
        }
        public void OnSuccess(T t)
        {
            IDisposable a = scheduler.ScheduleDirect(() =>
            {
                actual.OnSuccess(t);
            });

            DisposableHelper.Replace(ref this.t, a);
        }
Exemple #4
0
        public void OnComplete()
        {
            IDisposable t = scheduler.ScheduleDirect(() =>
            {
                actual.OnComplete();
            });

            DisposableHelper.Replace(ref task, t);
        }
Exemple #5
0
        public void OnError(Exception e)
        {
            IDisposable t = scheduler.ScheduleDirect(() =>
            {
                actual.OnError(e);
            });

            DisposableHelper.Replace(ref task, t);
        }
        public void OnSubscribe(IDisposable d)
        {
            if (OnSubscribeHelper.SetDisposable(ref this.d, d))
            {
                actual.OnSubscribe(this);

                IDisposable a = scheduler.ScheduleDirect(() => OnTimeout(), timeout);
                DisposableHelper.Replace(ref t, a);
            }
        }
 public void Request(long n)
 {
     if (SubscriptionHelper.Validate(n))
     {
         if (Interlocked.CompareExchange(ref once, 1, 0) == 0)
         {
             var d = scheduler.Schedule(Run);
             DisposableHelper.Replace(ref cancel, d);
         }
     }
 }
            public void OnSubscribe(ISubscription s)
            {
                var d = new FirstTimeout(this);

                if (DisposableHelper.Replace(ref this.d, d))
                {
                    firstTimeout.Subscribe(d);

                    arbiter.Set(s); // FIXME this races with the timeout switching to the fallback
                }
            }
            public void OnSubscribe(ISubscription s)
            {
                var d = new FirstTimeout(this);

                if (DisposableHelper.Replace(ref this.d, d))
                {
                    firstTimeout.Subscribe(d);

                    arbiter.Set(s);
                }
            }
Exemple #10
0
 public void OnError(Exception e)
 {
     if (delayError)
     {
         IDisposable a = scheduler.ScheduleDirect(() => actual.OnError(e), delay);
         DisposableHelper.Replace(ref this.t, a);
     }
     else
     {
         actual.OnError(e);
     }
 }
Exemple #11
0
        public void OnSubscribe(IDisposable d)
        {
            if (OnSubscribeHelper.SetDisposable(ref upstream, d))
            {
                actual.OnSubscribe(this);

                IDisposable t = scheduler.ScheduleDirect(() =>
                {
                    SubscribeOther();
                }, timeout);

                DisposableHelper.Replace(ref timer, t);
            }
        }
Exemple #12
0
            public void OnNext(T element)
            {
                Volatile.Read(ref timer)?.Dispose();

                long idx = Volatile.Read(ref index);

                if (Interlocked.CompareExchange(ref index, idx + 1, idx) == idx)
                {
                    produced++;

                    actual.OnNext(element);

                    DisposableHelper.Replace(ref timer, worker.Schedule(() => Timeout(idx + 1), itemTimeout));
                }
            }
 public IDisposable Schedule(Action task, TimeSpan initialDelay, TimeSpan period)
 {
     if (Volatile.Read(ref disposed) == 0)
     {
         InterruptibleAction ia = new InterruptibleAction(task, true);
         ia.parent = this;
         if (AddAction(ia))
         {
             var d = shared.Schedule(ia.Run, initialDelay, period);
             DisposableHelper.Replace(ref ia.resource, d);
             return(ia);
         }
     }
     return(EmptyDisposable.Instance);
 }
        IDisposable Schedule(Action task, TimeSpan delay, IWorkerServices worker = null)
        {
            if (Volatile.Read(ref state) != 2)
            {
                var run = runner;
                var t   = new InterruptibleAction(task);
                t.parent = worker;
                if (worker == null || worker.AddAction(t))
                {
                    var d = timed.Schedule(() =>
                    {
                        run.Offer(t.Run);
                    }, delay);

                    DisposableHelper.Replace(ref t.resource, d);

                    return(t);
                }
            }
            return(EmptyDisposable.Instance);
        }
            public bool TryOnNext(T t)
            {
                long idx = Volatile.Read(ref index);

                if (idx != long.MaxValue)
                {
                    if (Interlocked.CompareExchange(ref index, idx + 1, idx) == idx)
                    {
                        d?.Dispose();

                        produced++;

                        bool b = actual.TryOnNext(t);

                        IPublisher <V> p;

                        try
                        {
                            p = ObjectHelper.RequireNonNull(itemTimeout(t), "The itemTimeout returned a null IPublisher");
                        }
                        catch (Exception ex)
                        {
                            ExceptionHelper.ThrowIfFatal(ex);
                            arbiter.Cancel();
                            Interlocked.Exchange(ref index, long.MaxValue);
                            actual.OnError(ex);
                            return(false);
                        }
                        var dt = new ItemTimeout(this, idx + 1);
                        if (DisposableHelper.Replace(ref this.d, dt))
                        {
                            p.Subscribe(dt);
                        }

                        return(b);
                    }
                }
                return(false);
            }
 internal void SetTask(IDisposable d)
 {
     DisposableHelper.Replace(ref task, d);
 }
 internal void SetFuture(IDisposable d)
 {
     DisposableHelper.Replace(ref this.d, d);
 }
 public bool Set(IDisposable d)
 {
     return(DisposableHelper.Replace(ref this.d, d));
 }
Exemple #19
0
            public void OnComplete()
            {
                IDisposable a = second.Subscribe(this);

                DisposableHelper.Replace(ref d, a);
            }
Exemple #20
0
 public void Set(IDisposable d)
 {
     DisposableHelper.Replace(ref other, d);
 }
Exemple #21
0
 internal void SetUpstream(IDisposable d)
 {
     DisposableHelper.Replace(ref upstream, d);
 }
Exemple #22
0
 public void OnSubscribe(IDisposable d)
 {
     DisposableHelper.Replace(ref parent.upstream, d);
 }
Exemple #23
0
 public void OnSubscribe(IDisposable d)
 {
     DisposableHelper.Replace(ref this.d, d);
 }
 public void SetDisposable(IDisposable d)
 {
     DisposableHelper.Replace(ref this.d, d);
 }