Skip to content

Instantly share code, notes, and snippets.

@stdclass
Forked from 140bytes/LICENSE.txt
Created May 17, 2011 16:55
Show Gist options
  • Save stdclass/976843 to your computer and use it in GitHub Desktop.
Save stdclass/976843 to your computer and use it in GitHub Desktop.
Pub Sub
var pubsub = {t:{},sub:function(t,c,e){e=this;!e.t[t]&&(e.t[t]=[]);e.t[t].push(c);},pub:function(t,a,i,e){i=0;while(e=this.t[t][i++])e.apply({},a);}};
pubsub.sub("topic", function(p){
console.log("param: " + p);
});
pubsub.sub("topic", function(p){
console.log("param: " + p);
});
pubsub.pub("topic", ["a"]);
{t:{},sub:function(t,c,e){e=this;!e.t[t]&&(e.t[t]=[]);e.t[t].push(c);},pub:function(t,a,i,e){i=0;while(e=this.t[t][i++])e.apply({},a);}}
{
"name": "pubsub",
"keywords": [ "pubsub" ]
}
@jed
Copy link

jed commented May 20, 2011

What happens when you publish to a channel with no subscribers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment