PubSubThen is a synchronous publish/subscribe node.js module.
PubSubThen was developed for the purpose of complete separation of modules in node.js.
PubSubThen supports a synchronous topic publication.
There are several ways of getting PubSubThen
- Download a tagged version from GitHub
- Install via npm (
npm install pub-sub-then)
// RequirevarPubSubThen=require('../lib/PubSubThen');// Add a subscription to topicPubSubThen.subscribe('my-message',function(arg1,arg2,next){// Do something with arg1arg1.push('new value');// Do something with arg2arg2.push('new value 2');next();});// Publish the topicvarlist1=[];varlist2=[];PubSubThen.publish('my-message',list1,list2).then(function(){try{console.log(list1);console.log(list2);}catch(e){}},function(err){throwerr;});// Add a subscription to topicvarsubscription=PubSubThen.subscribe('my-message',function(args,next){// Do something next();});PubSubThen.unsubscribe('my-message',subscription);// Add a subscription to topicPubSubThen.subscribe('my-message',function(args,next){// FUNC 1next();});PubSubThen.subscribe('my-message',function(args,next){// FUNC 2next();});PubSubThen.removeAllSubscription('my-message');