4
4
function $TimeoutProvider ( ) {
5
5
this . $get = [ '$rootScope' , '$browser' , '$q' , '$$q' , '$exceptionHandler' ,
6
6
function ( $rootScope , $browser , $q , $$q , $exceptionHandler ) {
7
+
7
8
var deferreds = { } ;
8
9
9
10
@@ -16,15 +17,18 @@ function $TimeoutProvider() {
16
17
* block and delegates any exceptions to
17
18
* {@link ng.$exceptionHandler $exceptionHandler} service.
18
19
*
19
- * The return value of registering a timeout function is a promise, which will be resolved when
20
- * the timeout is reached and the timeout function is executed.
20
+ * The return value of calling `$ timeout` is a promise, which will be resolved when
21
+ * the delay has passed and the timeout function, if provided, is executed.
21
22
*
22
23
* To cancel a timeout request, call `$timeout.cancel(promise)`.
23
24
*
24
25
* In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to
25
26
* synchronously flush the queue of deferred functions.
26
27
*
27
- * @param {function() } fn A function, whose execution should be delayed.
28
+ * If you only want a promise that will be resolved after some specified delay
29
+ * then you can call `$timeout` without the `fn` function.
30
+ *
31
+ * @param {function()= } fn A function, whose execution should be delayed.
28
32
* @param {number= } [delay=0] Delay in milliseconds.
29
33
* @param {boolean= } [invokeApply=true] If set to `false` skips model dirty checking, otherwise
30
34
* will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
@@ -33,6 +37,12 @@ function $TimeoutProvider() {
33
37
*
34
38
*/
35
39
function timeout ( fn , delay , invokeApply ) {
40
+ if ( ! isFunction ( fn ) ) {
41
+ invokeApply = delay ;
42
+ delay = fn ;
43
+ fn = noop ;
44
+ }
45
+
36
46
var skipApply = ( isDefined ( invokeApply ) && ! invokeApply ) ,
37
47
deferred = ( skipApply ? $$q : $q ) . defer ( ) ,
38
48
promise = deferred . promise ,
0 commit comments