cancellation

Cancel a vanilla ECMAScript 6 Promise chain

送分小仙女□ 提交于 2019-11-26 00:43:16
问题 Is there a method for clearing the .then s of a JavaScript Promise instance? I\'ve written a JavaScript test framework on top of QUnit. The framework runs tests synchronously by running each one in a Promise . (Sorry for the length of this code block. I commented it as best I can, so it feels less tedious.) /* Promise extension -- used for easily making an async step with a timeout without the Promise knowing anything about the function it\'s waiting on */ $$.extend(Promise, { asyncTimeout:

How to cancel an $http request in AngularJS?

◇◆丶佛笑我妖孽 提交于 2019-11-26 00:13:22
问题 Given a Ajax request in AngularJS $http.get(\"/backend/\").success(callback); what is the most effective way to cancel that request if another request is launched (same backend, different parameters for instance). 回答1: This feature was added to the 1.1.5 release via a timeout parameter: var canceler = $q.defer(); $http.get('/someUrl', {timeout: canceler.promise}).success(successCallback); // later... canceler.resolve(); // Aborts the $http request if it isn't finished. 回答2: Cancelling Angular