| 1 |
dojo.provide("dojox.lang.async.timeout"); |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
(function(){ |
| 6 |
var d = dojo, timeout = dojox.lang.async.timeout; |
| 7 |
|
| 8 |
timeout.from = function(ms){ |
| 9 |
return function(){ |
| 10 |
var h, cancel = function(){ |
| 11 |
if(h){ |
| 12 |
clearTimeout(h); |
| 13 |
h = null; |
| 14 |
} |
| 15 |
}, |
| 16 |
x = new d.Deferred(cancel); |
| 17 |
h = setTimeout(function(){ |
| 18 |
cancel(); |
| 19 |
x.callback(ms); |
| 20 |
}, ms); |
| 21 |
return x; |
| 22 |
}; |
| 23 |
}; |
| 24 |
|
| 25 |
timeout.failOn = function(ms){ |
| 26 |
return function(){ |
| 27 |
var h, cancel = function(){ |
| 28 |
if(h){ |
| 29 |
clearTimeout(h); |
| 30 |
h = null; |
| 31 |
} |
| 32 |
}, |
| 33 |
x = new d.Deferred(cancel); |
| 34 |
h = setTimeout(function(){ |
| 35 |
cancel(); |
| 36 |
x.errback(ms); |
| 37 |
}, ms); |
| 38 |
return x; |
| 39 |
}; |
| 40 |
}; |
| 41 |
})(); |