source: Dev/branches/rest-dojo-ui/client/dojox/lang/async/timeout.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 703 bytes
Line 
1dojo.provide("dojox.lang.async.timeout");
2
3// Source of Deferred for timeouts
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})();
Note: See TracBrowser for help on using the repository browser.