vizz.async-client

2.0.0 • Public • Published

Publish / Subscribe Client (Support to generators)

Now only support to Redis. In the future we may add support for the AMQP protocol.

Install

npm install --save vizz.async-client-nodejs

Use

You have examples in examples folder. To execute example: npm run example

Code:

'use strict';
const CHANNEL = 'myChannel';

function* iter(number) {
    for (var i = 0; i < number; i++) {
        yield i;
    }
}

function* gen(number) {
    for (var val of iter(number)) {
        console.log(val);
    }
}

var AsyncClient = require('../index');

var asyncClientPublish = new AsyncClient(AsyncClient.REDIS, {
    host: 'localhost' // redis url
});
var asyncClientSubscriber = new AsyncClient(AsyncClient.REDIS, {
    host: 'localhost'// redis url
});

var channelSubscribe = asyncClientSubscriber.toChannel(CHANNEL);
channelSubscribe.on('message', function*(channel, message) {
                                   console.log('Message received: ' + message);
                                   yield gen(message);
                                   console.log('Message completed');
});
channelSubscribe.subscribe();

asyncClientPublish.toChannel(CHANNEL).emit(2);
asyncClientPublish.toChannel(CHANNEL).emit(5);

Readme

Keywords

none

Package Sidebar

Install

npm i vizz.async-client

Weekly Downloads

3

Version

2.0.0

License

MIT

Unpacked Size

20.3 kB

Total Files

18

Last publish

Collaborators

  • raul.requero