A publisher subscriber library
npm install pub-sub-then


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)
``javascript
// Require
var PubSubThen = require('../lib/PubSubThen');
// Add a subscription to topic
PubSubThen.subscribe('my-message', function(arg1, arg2, next) {
// Do something with arg1
arg1.push('new value');
// Do something with arg2
arg2.push('new value 2');
next();
});
// Publish the topic
var list1 = [];
var list2 = [];
PubSubThen.publish('my-message', list1, list2).then(
function() {
try {
console.log(list1);
console.log(list2);
} catch(e) {
}
},
function(err) {
throw err;
}
);
`
`javascript
// Add a subscription to topic
var subscription = PubSubThen.subscribe('my-message', function(args, next) {
// Do something
next();
});
PubSubThen.unsubscribe('my-message', subscription);
`
`javascript
// Add a subscription to topic
PubSubThen.subscribe('my-message', function(args, next) {
// FUNC 1
next();
});
PubSubThen.subscribe('my-message', function(args, next) {
// FUNC 2
next();
});
PubSubThen.removeAllSubscription('my-message');
``
* The Many Faces of Publish/Subscribe (PDF)
* Addy Osmani's mini book on Patterns
* Publish / Subscribe Systems, A summary of 'The Many Faces of Publish / Subscribe'
MIT: http://codeflyer.mit-license.org/