public void Basic()
        {
            var sad = new akarnokd.reactive_extensions.SingleAssignmentDisposable();

            Assert.IsNull(sad.Disposable);

            var count = 0;

            sad.Disposable = Disposable.Create(() => count++);

            Assert.IsNotNull(sad.Disposable);

            sad.Dispose();

            Assert.IsNotNull(sad.Disposable);

            Assert.AreEqual(DisposableHelper.EMPTY, sad.Disposable);
        }
        public void Multi_Assign()
        {
            var sad = new akarnokd.reactive_extensions.SingleAssignmentDisposable();

            sad.Disposable = DisposableHelper.EMPTY;

            var count = 0;

            try
            {
                sad.Disposable = Disposable.Create(() => count++);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }

            Assert.AreEqual(1, count);
        }
Пример #3
0
            internal void Next(IObservable <T> first)
            {
                if (Interlocked.Increment(ref wip) == 1)
                {
                    do
                    {
                        var sad = new SingleAssignmentDisposable();
                        if (Interlocked.CompareExchange(ref upstream, sad, null) == null)
                        {
                            if (first != null)
                            {
                                sad.Disposable = first.Subscribe(this);
                                first          = null;
                            }
                            else
                            {
                                if (index == fallbacks.Length)
                                {
                                    downstream.OnCompleted();
                                }
                                else
                                {
                                    var src = fallbacks[index];
                                    if (src != null)
                                    {
                                        fallbacks[index] = null;

                                        index++;
                                        sad.Disposable = src.Subscribe(this);
                                    }
                                    else
                                    {
                                        downstream.OnError(new NullReferenceException("The fallbacks[" + index + "] is null"));
                                    }
                                }
                            }
                        }
                    }while (Interlocked.Decrement(ref wip) != 0);
                }
            }
Пример #4
0
 internal bool SetDisposable(SingleAssignmentDisposable sad)
 {
     return(Interlocked.CompareExchange(ref upstream, sad, null) == null);
 }
Пример #5
0
 static InnerObserver()
 {
     DISPOSED = new SingleAssignmentDisposable();
     DISPOSED.Dispose();
 }