Hey guys, I have a project with heavy promises use where sometimes I use $timeout to get set a timer for my calls (this is pseudocode just for the example, please don't focus on it)
firstPromise([
$http.get('/foo/bar'),
$timeout(angular.noop, 1500),
]).then(function() {
// ...
});
I saw in documentation $timeout arguments are optional but if I pass no function when timer arrives I get "TypeError: fn is not a function".
> $timeout(1000)
< Promise {$$state: Object, $$timeoutId: 187}
app-bootstrap.js:16 TypeError: fn is not a function
at angular.js:16299
at completeOutstandingRequest (angular.js:4924)
at angular.js:5312(anonymous function) @ app-bootstrap.js:16(anonymous function) @ angular.js:16302completeOutstandingRequest @ angular.js:4924(anonymous function) @ angular.js:5312
> $timeout()
< Promise {$$state: Object, $$timeoutId: 188}
app-bootstrap.js:16 TypeError: fn is not a function
at angular.js:16299
at completeOutstandingRequest (angular.js:4924)
at angular.js:5312
My question is: as $timeout returns a promise can we use argument type detection to use angular.noop if first argument is a number?
$timeout(10000); // equals to $timeout(angular.noop, 1000)
Which will allow us to chain this promise with others in a more readable way.
What do you think?