topic.js 851 B

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