Skip to content

tlghn/soprano.pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

soprano.pubsub

Publish / Subscription protocol for soprano

Install

npm i soprano.pubsub --save

Examples

Basic

server.js

const Soprano = require('soprano');
const PubSubProtocol = require('soprano.pubsub');

const soprano = new Soprano();
const pubSub = new PubSubProtocol(soprano);

(async function () {
    await soprano.bind(pubSub);
    let server = await soprano.listen();

    while(true){
        await Soprano.utils.sleep(1000);
        await pubSub.publish('channelName', 'Hello World');
    }
})();

client.js

const Soprano = require('soprano');
const PubSubProtocol = require('soprano.pubsub');

(async function () {
    const soprano = new Soprano();
    const pubSub = new PubSubProtocol(soprano);
    let controller = await pubSub.connect();

    controller.on('message', function(channel){
        console.log(arguments);
    });

    // Subscription
    let subscribedChannelCount = await controller.subscribe('channelName', 'channelName2');
    console.log(subscribedChannelCount);

    // Unsubscription
    subscribedChannelCount = await controller.unsubscribe('channelName2');
    console.log(subscribedChannelCount);
});

More Examples ?

Please see the tests directory

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published