예제 #1
0
파일: FutureTests.cs 프로젝트: sq/Libraries
        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);
        }
예제 #2
0
            protected void EventHandler(IEventInfo e)
            {
                if (_IsCompleted)
                {
                    return;
                }

                // Events that don't match are silently rejected.
                // FIXME: Is this actually horrible
                if (!TryExtractResult(e, out Result))
                {
                    return;
                }

                e.Consume();
                _IsCompleted = true;
                Dispose();

                if (Continuation != null)
                {
                    Continuation();
                }

                if (_Future != null)
                {
                    _Future.SetResult(Result, null);
                }
            }
예제 #3
0
 public void Execute()
 {
     try {
         var result = Func();
         Future.SetResult(result, null);
     } catch (Exception exc) {
         Future.SetResult2(default(T), ExceptionDispatchInfo.Capture(exc));
     }
 }
예제 #4
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);
        }
예제 #5
0
 public static void Complete <T> (this Future <T> future, T result)
 {
     future.SetResult(result, null);
 }