public void DisposeOnScheduler()
        {
            int i = 0;
            var d = new ScheduledDisposable (Scheduler.ThreadPool, Disposable.Create (() => { Thread.Sleep (200); i++; }));
            d.Dispose ();
            Assert.AreEqual (0, i, "#1");
            Assert.IsTrue (d.IsDisposed, "#2");
            Assert.IsTrue (SpinWait.SpinUntil (() => i != 0, 1000), "#3");

            d = new ScheduledDisposable (Scheduler.Immediate, Disposable.Create (() => { Thread.Sleep (200); i++; }));
            d.Dispose ();
            Assert.AreEqual (2, i, "#4"); // disposes immediately, so it must be already 2.
        }
Example #2
0
        public void ScheduledDisposable()
        {
            var d = new BooleanDisposable();
            var s = new ScheduledDisposable(Scheduler.Immediate, d);

            Assert.IsFalse(d.IsDisposed);

            Assert.AreSame(Scheduler.Immediate, s.Scheduler);
            Assert.AreSame(d, s.Disposable);

            s.Dispose();

            Assert.IsTrue(d.IsDisposed);
            Assert.IsTrue(s.IsDisposed);

            Assert.AreSame(Scheduler.Immediate, s.Scheduler);
            //Assert.AreSame(d, s.Disposable); // BREAKING CHANGE v2 > v1.x - Undefined behavior after disposal.
            s.Disposable.Dispose();            // This should be a nop.
        }