public void Async_HappyCase() { bool asyncSubscription = false; Exception ex = null; EventBus.Subscribe <Exception>((e) => ex = e); Delegate <TestEvent> handler = (TestEvent args) => { Thread.Sleep(1); asyncSubscription = true; }; EventBus.Subscribe(handler.Async()); EventBus.Publish(new TestEvent(), this); Assert.IsFalse(asyncSubscription); waitFor(() => asyncSubscription); Assert.IsNull(ex); }
public void Async_ExceptionInHandler_ThrowsException() { bool asyncSubscription = false; Exception ex = null; EventBus.Subscribe <Exception>((e) => ex = e); Delegate <TestEvent> handler = (TestEvent args) => { throw new InvalidOperationException(); }; EventBus.Subscribe( handler.Async() ); EventBus.Publish <TestEvent>(new TestEvent(), this); Assert.IsFalse(asyncSubscription); waitFor(() => ex != null); Assert.IsFalse(asyncSubscription); Assert.AreEqual(ex.GetType(), typeof(InvalidOperationException)); }
public static Task <object> DynamicInvokeAsync(this Delegate action, params object[] parameters) => action.Async(parameters, (d, p) => d.DynamicInvoke(p));