Home >Web Front-end >JS Tutorial >Can ECMAScript 6 Promises Be Cancelled?
Is there a way to remove the .thens from a JavaScript Promise instance?
ECMAscript 6 Promises are not cancellable by default. Despite ongoing discussions, there is no official solution in ES6.
Alternatives:
Current Solution for Unblocking Tests:
Implement a custom cancelTest flag within the test framework that polls for cancellation requests. When the timeout occurs, set cancelTest to true and call assert.fail() to mark the test as failed.
Further Updates:
After resolving the initial issue (an uncaught error during fn.call()), the then() statement was not being called due to an uncaught error in the test function itself. By catching the error, the test promise can resolve gracefully, allowing the test to finish and the then() statement to execute.
The above is the detailed content of Can ECMAScript 6 Promises Be Cancelled?. For more information, please follow other related articles on the PHP Chinese website!