timeout.js 821 B

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