public void PromiseIsCanceledFromToken() { CancelationSource cancelationSource = CancelationSource.New(); var deferred = Promise.NewDeferred(); var deferredInt = Promise.NewDeferred <int>(); int cancelCallbacks = 0; TestHelper.AddResolveCallbacksWithCancelation <float, string>( deferred.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddCallbacksWithCancelation <float, object, string>( deferred.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddContinueCallbacksWithCancelation <float, string>( deferred.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddResolveCallbacksWithCancelation <int, float, string>( deferredInt.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddCallbacksWithCancelation <int, float, object, string>( deferredInt.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddContinueCallbacksWithCancelation <int, float, string>( deferredInt.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); cancelationSource.Cancel(); deferred.Resolve(); deferredInt.Resolve(1); Promise.Manager.HandleCompletes(); Assert.AreEqual( TestHelper.cancelVoidCallbacks + TestHelper.cancelTCallbacks, cancelCallbacks ); cancelationSource.Dispose(); TestHelper.Cleanup(); }
public void OnContinueIsNotInvokedIfTokenIsAlreadyCanceled() { CancelationSource cancelationSource = CancelationSource.New(); cancelationSource.Cancel(); var deferred = Promise.NewDeferred(); var deferredInt = Promise.NewDeferred <int>(); TestHelper.AddContinueCallbacksWithCancelation <float, string>( deferred.Promise, onContinue: _ => Assert.Fail("OnContinue was invoked."), onContinueCapture: (_, __) => Assert.Fail("OnContinue was invoked."), cancelationToken: cancelationSource.Token ); TestHelper.AddContinueCallbacksWithCancelation <int, float, string>( deferredInt.Promise, onContinue: _ => Assert.Fail("OnContinue was invoked."), onContinueCapture: (_, __) => Assert.Fail("OnContinue was invoked."), cancelationToken: cancelationSource.Token ); deferred.Resolve(); deferredInt.Resolve(1); Promise.Manager.HandleCompletes(); cancelationSource.Dispose(); TestHelper.Cleanup(); }