예제 #1
0
            public void OnCompleted(Action continuation)
            {
                var oc = Registration.OnComplete(continuation);

                Future.RegisterOnComplete(oc);
                Future.RegisterOnDispose((f) => oc(f));
            }
예제 #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);
        }
예제 #3
0
        public void InvokesOnCompletesWhenCompleted()
        {
            var    f = new Future <object>();
            object completeResult = null;

            f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
            f.Complete(5);
            Assert.AreEqual(5, completeResult);
        }
예제 #4
0
        public void IfOnCompleteRegisteredAfterAlreadyCompletedCalledAnyway()
        {
            var    f = new Future <object>();
            object completeResult = null;

            f.Complete(5);
            f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
            Assert.AreEqual(5, completeResult);
        }
예제 #5
0
파일: Util.cs 프로젝트: jli94/Fracture
 public StoreResult(
     IEnumerator <object> task, Expression <Func <T> > target,
     TaskExecutionPolicy executionPolicy = TaskExecutionPolicy.RunWhileFutureLives
     )
 {
     _Task            = task;
     _Thunk           = new SchedulableGeneratorThunk(_Task);
     _ExecutionPolicy = executionPolicy;
     _Future          = Future.New <T>();
     _Future.Bind(target);
     _Future.RegisterOnComplete(Completed);
 }
예제 #6
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);
        }
예제 #7
0
        public void Start <T> (Future <T> future, ISchedulable <T> task, TaskExecutionPolicy executionPolicy)
        {
            using (IsActive)
                task.Schedule(this, future);

            switch (executionPolicy)
            {
            case TaskExecutionPolicy.RunAsBackgroundTask:
                future.RegisterOnComplete(BackgroundTaskOnComplete);
                break;

            default:
                break;
            }
        }
예제 #8
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.IsInstanceOfType(typeof(Exception), fhe.InnerException);
                Assert.AreEqual("pancakes", fhe.InnerException.Message);
            }
        }