Beispiel #1
0
 public void Dispose()
 {
     lock (this)
         if (_Current != null)
         {
             _Current.Dispose();
             _Current = null;
         }
 }
        public void IfCompletedDisposeHasNoEffect()
        {
            var f = new Future <object>();

            f.Complete(5);
            f.Dispose();
            Assert.AreEqual(5, f.Result);
            Assert.IsFalse(f.Disposed);
        }
        public void CannotBeCompletedIfDisposedFirst()
        {
            var f = new Future <object>();

            f.Dispose();
            Assert.IsTrue(f.Disposed);
            f.Complete(5);
            Assert.IsTrue(f.Disposed);
            Assert.IsFalse(f.Completed);
        }
        public void DisposingFutureInvokesOnDisposeHandlers()
        {
            bool[] invoked = new bool[1];

            var f = new Future <object>();

            f.RegisterOnDispose((_) => {
                invoked[0] = true;
            });

            f.Dispose();
            Assert.IsTrue(invoked[0]);
        }
        public void FutureWrapsExceptionIfOnDisposeHandlerThrows()
        {
            var f = new Future <object>();

            f.RegisterOnDispose((_) => {
                throw new Exception("pancakes");
            });

            try {
                f.Dispose();
                Assert.Fail("Exception was swallowed");
            } catch (FutureHandlerException fhe) {
                Assert.IsInstanceOfType(typeof(Exception), fhe.InnerException);
                Assert.AreEqual("pancakes", fhe.InnerException.Message);
            }
        }
Beispiel #6
0
            public void OnDispose(IFuture f)
            {
                bool completed = false;

                lock (State) {
                    if (State.Count == Trigger)
                    {
                        completed = true;
                        State.Clear();
                    }
                    else
                    {
                        State.Remove(f);
                    }
                }

                if (completed)
                {
                    Composite.Dispose();
                }
            }