Skip to content

Commit

Permalink
Add a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEtco committed Sep 2, 2019
1 parent b0579d8 commit 9907a8f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/redis-bus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const Redis = require('ioredis')

/**
* This class extends the EventEmitter to act as a pub/sub message bus,
* allowing payloads to be received by one instance of Smee and sent by
* others. This allows Smee to be multi-instanced!
*/
module.exports = class RedisBus {
/**
* @param {import('events').EventEmitter} events
*/
constructor (events) {
this.events = events
this.opts = {
Expand All @@ -20,6 +28,9 @@ module.exports = class RedisBus {
this.sub.on('message', (_, message) => this.emitRemoteEvent(message))
}

/**
* Emit an even to this machine's in-memory EventEmitter
*/
emitLocalEvent (message) {
const json = JSON.parse(message)
return this.events.emit(json.channel, json.payload)
Expand Down

0 comments on commit 9907a8f

Please sign in to comment.