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); }
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); } }
public void Execute() { try { var result = Func(); Future.SetResult(result, null); } catch (Exception exc) { Future.SetResult2(default(T), ExceptionDispatchInfo.Capture(exc)); } }
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); }
public static void Complete <T> (this Future <T> future, T result) { future.SetResult(result, null); }