Promise returned from $timeout should not be chained because $$timeoutId is lost #16424
Description
I'm submitting a ...
- bug report
- feature request
- other
Current behavior:
$timeout
returns a promise
that has been "decorated" with a $$timeoutId
that is then required when attempting to cancel the timeout via $timeout.cancel(promise)
. When chaining to this promise upon creation (i.e. then
, catch
, and/or finally
), the promise returned from the chained function(s) is a new promise that does not contain $$timeoutId
.
Expected / new behavior:
Ideally, Angular.js would not be adding properties willy-nilly to this promise. Secondly, it would be great if the chained calls would return back any extra properties set on the original promise (i.e. $$timeoutId
). BUT, it would suffice if the documentation for $timeout
could be enhanced to provide a note about this limitation.
Minimal reproduction of the problem with instructions:
Plnkr - Take note that this is built with a chained catch
and causes the timeout to not be canceled. If you remove the chained catch
or move the catch
to a separate line after initial assignment, it cancels just fine.
AngularJS version:
1.6.6
Browser:
All
Anything else:
I strongly would consider this a defect but because I don't think you're going to change your underlying then
, catch
, and finally
implementation to copy any ole' properties from the chained promise, documentation would suffice for any other future souls.
The guilty line of code is here: https://github.com/angular/angular.js/blob/master/src/ng/timeout.js#L66