Пример #1
0
        public void TestGetResultMethodNeverThrows()
        {
            var       f = new Future <object>();
            object    result;
            Exception error;

            Assert.IsFalse(f.GetResult(out result, out error));

            f.SetResult(5, null);
            Assert.IsTrue(f.GetResult(out result, out error));
            Assert.AreEqual(5, result);

            f = new Future <object>();

            f.SetResult(null, new Exception("earth-shattering kaboom"));
            Assert.IsTrue(f.GetResult(out result, out error));
            Assert.IsTrue(error is Exception);
        }
Пример #2
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);
        }