pub-sub-then

0.1.5 • Public • Published

PubSubThen

Build Status GitHub version

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.

Getting PubSubThen

There are several ways of getting PubSubThen

Examples

Basic example

// 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;
    }
);

Unsubscribe

// Add a subscription to topic
var subscription = PubSubThen.subscribe('my-message', function(args, next) {
    // Do something 
    
    next();
});
 
PubSubThen.unsubscribe('my-message', subscription);

Cancel all subscriptions for a message

// 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');

More about Publish/Subscribe

License

MIT: http://codeflyer.mit-license.org/

Package Sidebar

Install

npm i pub-sub-then

Weekly Downloads

2

Version

0.1.5

License

MIT

Last publish

Collaborators

  • davidefiorello