1
1
# [ jQuery Timeout Plugin] ( https://github.com/tkem/jquery-timeout/ )
2
2
3
- ** jQuery 1.5** introduced the _ Deferred_ callback management system,
4
- to ease handling callbacks for asynchronous events. Although the
5
- jQuery documentation contains examples on how to use Deferred objects
6
- with the native ` window.setTimeout ` and ` window.clearTimeout `
3
+ ** jQuery 1.5** introduced the [ Deferred
4
+ Object] ( http://api.jquery.com/category/deferred-object/ ) to ease
5
+ handling callbacks for asynchronous events. Although the jQuery
6
+ documentation contains examples on how to use Deferred objects with
7
+ the native ` window.setTimeout() ` and ` window.clearTimeout() `
7
8
functions, jQuery does not provide a simple interface for timer-based
8
9
Deferreds yet.
9
10
10
- This plugin provides the two functions ` jQuery.timeout ` and
11
- ` jQuery.timeoutWith ` that, given a delay in milliseconds, create a
11
+ This plugin provides the two functions ` jQuery.timeout() ` and
12
+ ` jQuery.timeoutWith() ` that, given a delay in milliseconds, create a
12
13
` jQuery.Deferred ` instance that will be resolved after the given
13
- delay. The returned Promise object also provides ` clear ` and
14
- ` clearWith ` methods, which will reject the Deferred object and clear
14
+ delay. The returned Promise object also provides ` clear() ` and
15
+ ` clearWith() ` methods, which will reject the Deferred object and clear
15
16
the native timeout ID, if called before the timeout has elapsed.
16
17
17
18
@@ -21,24 +22,32 @@ the native timeout ID, if called before the timeout has elapsed.
21
22
22
23
Create a Deferred object that will be resolved after the specified
23
24
` delay ` in milliseconds. When the Deferred is resolved, any
24
- doneCallbacks are called with optional arguments ` args ` .
25
+ doneCallbacks are called with optional arguments ` args ` . The returned
26
+ ` Timeout ` object extends the Deferred's Promise object with the
27
+ addional methods ` clear() ` and ` clearWith() ` , for rejecting the
28
+ Deferred before the delay has elapsed.
25
29
26
30
### jQuery.timeoutWith( delay, context [ , args ] )
27
31
28
32
Create a Deferred object that will be resolved after the specified
29
33
` delay ` in milliseconds. When the Deferred is resolved, any
30
34
doneCallbacks are called with the given ` context ` as the ` this `
31
- object, and the optional array ` args ` as arguments.
35
+ object, and the optional array ` args ` as arguments. The returned
36
+ ` Timeout ` object extends the Deferred's Promise object with the
37
+ addional methods ` clear() ` and ` clearWith() ` , for rejecting the
38
+ Deferred before the delay has elapsed.
32
39
33
40
### timeout.clear( [ args... ] )
34
41
35
- Clear a pending timeout by immediately rejecting the corresponding
42
+ Clear a pending Promise object returned by ` jQuery.timeout() ` or
43
+ ` jQuery.timeoutWith() ` by immediately rejecting the corresponding
36
44
Deferred object. When the Deferred is rejected, any failCallbacks are
37
45
called with optional arguments ` args ` .
38
46
39
47
### timeout.clearWith( context [ , args ] )
40
48
41
- Clear a pending timeout by immediately rejecting the corresponding
49
+ Clear a pending Promise object returned by ` jQuery.timeout() ` or
50
+ ` jQuery.timeoutWith() ` by immediately rejecting the corresponding
42
51
Deferred object. When the Deferred is rejected, any failCallbacks are
43
52
called with the given ` context ` as the ` this ` object, and the optional
44
53
array ` args ` as arguments.
@@ -69,12 +78,10 @@ timeout.
69
78
70
79
```
71
80
var timeout = $.timeout( 10000 );
72
-
73
81
timeout.then(
74
82
function() { alert( "timeout elapsed" ) },
75
83
function() { alert( "timeout cleared" ) }
76
84
);
77
-
78
85
$( "#clear" ).click(function() {
79
86
timeout.clear();
80
87
});
0 commit comments