Esempio n. 1
0
        public void InvokesOnCompletesWhenCompleted()
        {
            var    f = new Future <object>();
            object completeResult = null;

            f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
            f.Complete(5);
            Assert.AreEqual(5, completeResult);
        }
Esempio n. 2
0
        public void InvokesOnCompletesWhenFailed()
        {
            var    f = new Future <object>();
            object completeResult = null;

            f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
            f.Fail(new Exception("test"));
            Assert.AreEqual("test", (completeResult as Exception).Message);
        }
Esempio n. 3
0
        public void IfOnCompleteRegisteredAfterAlreadyCompletedCalledAnyway()
        {
            var    f = new Future <object>();
            object completeResult = null;

            f.Complete(5);
            f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
            Assert.AreEqual(5, completeResult);
        }
Esempio n. 4
0
        public static Future <T> Bind <T> (this Future <T> future, Expression <Func <T> > target)
        {
            var member = BoundMember.New(target);

            future.RegisterOnComplete((_) => {
                T result;
                if (future.GetResult(out result))
                {
                    member.Value = result;
                }
            });

            return(future);
        }
Esempio n. 5
0
        public void FutureWrapsExceptionIfOnCompleteHandlerThrows()
        {
            var f = new Future <object>();

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

            try {
                f.Complete(1);
                Assert.Fail("Exception was swallowed");
            } catch (FutureHandlerException fhe) {
                Assert.IsInstanceOf <Exception>(fhe.InnerException);
                Assert.AreEqual("pancakes", fhe.InnerException.Message);
            }
        }