Debian Codegraph @

dojox/lang/async/topic.js

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