Esempio n. 1
0
        public void InvokesOnResolvedWhenCompleted()
        {
            var    f1             = new Future <int>();
            var    f2             = new Future <int>();
            var    f3             = new Future <int>();
            object completeResult = null;
            var    handler        = (OnFutureResolved <int>)(
                (f) => {
                completeResult =
                    (f.Disposed)
                            ? "disposed"
                            : (f.Failed
                                ? f.Error
                                : (object)f.Result
                               );
            }
                );

            f1.RegisterOnResolved2(handler);
            f1.Complete(5);
            Assert.AreEqual(5, completeResult);
            f2.RegisterOnResolved2(handler);
            f2.Dispose();
            Assert.AreEqual("disposed", completeResult);
            f3.RegisterOnResolved2(handler);
            var exc = new Exception("test");

            f3.SetResult(0, exc);
            Assert.AreEqual(exc, completeResult);
        }
Esempio n. 2
0
        public void IfCompletedDisposeHasNoEffect()
        {
            var f = new Future <object>();

            f.Complete(5);
            f.Dispose();
            Assert.AreEqual(5, f.Result);
            Assert.IsFalse(f.Disposed);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void DisposingFutureInvokesOnDisposeHandlers()
        {
            bool[] invoked = new bool[1];

            var f = new Future <object>();

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

            f.Dispose();
            Assert.IsTrue(invoked[0]);
        }
Esempio n. 5
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.IsInstanceOf <Exception>(fhe.InnerException);
                Assert.AreEqual("pancakes", fhe.InnerException.Message);
            }
        }
Esempio n. 6
0
        public void RegisteringHandlersOnDisposedFutureWorks()
        {
            bool[] invoked = new bool[4];

            var f = new Future <object>();

            f.RegisterHandlers(
                (_) => invoked[0] = true,
                (_) => invoked[1] = true
                );
            f.Dispose();
            f.RegisterHandlers(
                (_) => invoked[2] = true,
                (_) => invoked[3] = true
                );

            Assert.IsFalse(invoked[0]);
            Assert.IsTrue(invoked[1]);
            Assert.IsFalse(invoked[2]);
            Assert.IsTrue(invoked[3]);
        }
Esempio n. 7
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();
                }
            }