cxPubSub

cxPubSub

Global Publish / Subscribe messaging bus

Example

const {publish, subscribe} = require('cxPubSub');
async function main(data) {
  subscribe('myEvent', (data) => {
    console.log(data);
  })
  publish('myEvent', {my: 'data'})
  return {a, b};
}

Methods

(static) publish(params, params) → {Promise}

Description:
  • Publish

Example
publish('myEvent', '1234', {my: 'data'});
Parameters:
Name Type Description
params string

Event Name

params object

Payload

Returns:
Type
Promise

(static) subscribe(channel, id, callback) → {EventEmitter}

Description:
  • Subscribe

Example
subscribe('myEvent', '1234', (data) => {
  console.log(data);
});
Parameters:
Name Type Description
channel string

Channel

id string

ID

callback callback

Callback Function

Returns:
Type
EventEmitter