public void OnCompleted(Action continuation) { var oc = Registration.OnComplete(continuation); Future.RegisterOnComplete(oc); Future.RegisterOnDispose((f) => oc(f)); }
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); }
public void InvokesOnCompletesWhenCompleted() { var f = new Future <object>(); object completeResult = null; f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; }); f.Complete(5); Assert.AreEqual(5, completeResult); }
public void IfOnCompleteRegisteredAfterAlreadyCompletedCalledAnyway() { var f = new Future <object>(); object completeResult = null; f.Complete(5); f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; }); Assert.AreEqual(5, completeResult); }
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); }
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); }
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; } }
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); } }