This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($timeout/$interval): throw when trying to cancel non-$timeout/$interval promise #16476
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4fe3127
to
3cb3ac0
Compare
mgol
approved these changes
Mar 12, 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Maybe you could land the big indentation change in src/ng/interval.js
separately but no biggie.
Narretz
suggested changes
Mar 13, 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also like to see the indentation changes in a separate commit :>
Previously, calling `$timeout.cancel()` with a promise that was not generated by a call to `$timeout()` would do nothing. This could, for example, happen when calling `.then()`/`.catch()` on the returned promise, which creates a new promise, and passing that to `$timeout.cancel()`. With this commit, `$timeout.cancel()` will throw an error if called with a non-$timeout promise, thus surfacing errors that would otherwise go unnoticed. Fixes angular#16424 BREAKING CHNAGE: `$timeout.cancel()` will throw an error if called with a promise that was not generated by `$timeout()`. Previously, it would silently do nothing. Before: ```js var promise = $timeout(doSomething, 1000).then(doSomethingElse); $timeout.cancel(promise); // No error; timeout NOT canceled. ``` After: ```js var promise = $timeout(doSomething, 1000).then(doSomethingElse); $timeout.cancel(promise); // Throws error. ``` Correct usage: ```js var promise = $timeout(doSomething, 1000); var newPromise = promise.then(doSomethingElse); $timeout.cancel(promise); // Timeout canceled. ```
Previously, calling `$interval.cancel()` with a promise that was not generated by a call to `$interval()` would do nothing. This could, for example, happen when calling `.then()`/`.catch()` on the returned promise, which creates a new promise, and passing that to `$interval.cancel()`. With this commit, `$interval.cancel()` will throw an error if called with a non-$interval promise, thus surfacing errors that would otherwise go unnoticed. Related to angular#16424. BREAKING CHNAGE: `$interval.cancel()` will throw an error if called with a promise that was not generated by `$interval()`. Previously, it would silently do nothing. Before: ```js var promise = $interval(doSomething, 1000, 5).then(doSomethingElse); $interval.cancel(promise); // No error; interval NOT canceled. ``` After: ```js var promise = $interval(doSomething, 1000, 5).then(doSomethingElse); $interval.cancel(promise); // Throws error. ``` Correct usage: ```js var promise = $interval(doSomething, 1000, 5); var newPromise = promise.then(doSomethingElse); $interval.cancel(promise); // Interval canceled. ```
3cb3ac0
to
7867a94
Compare
Moved indentation fixes to separate commits. |
mgol
approved these changes
Mar 13, 2018
Narretz
approved these changes
Mar 13, 2018
Thanks for getting on this so quickly. I have a unit test in my app to prevent this in the future but certainly helps to have an exception safeguard! |
gkalpak
added a commit
to gkalpak/angular.js
that referenced
this pull request
May 5, 2018
gkalpak
added a commit
that referenced
this pull request
May 5, 2018
gkalpak
added a commit
to gkalpak/angular.js
that referenced
this pull request
May 5, 2018
gkalpak
added a commit
that referenced
this pull request
May 5, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix (sort of).
What is the current behavior? (You can also link to an open issue here)
Calling
$timeout/$interval.cancel()
with a non-$timeout/$interval promise silently does nothing.This can for example happen, when calling
.then()
/.catch()
on the returned promise, which creates a new promise and use that new promise for cancelling.What is the new behavior (if this is a feature change)?
Passing a non-$timeout/$interval promise to
$timeout/$interval.cancel()
throws an error.This will help catching issues tht would otherwise go unnoticed.
Does this PR introduce a breaking change?
Yes.
Please check if the PR fulfills these requirements
Other information:
Fixes #16424.