Skip to content

Commit 1804860

Browse files
author
Marvel Mathew
committed
Add option for disabling fan out
1 parent f98a0f7 commit 1804860

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class Publisher {
3939

4040
class Subscriber extends events.EventEmitter {
4141

42-
constructor() {
42+
constructor(options) {
4343
super();
44+
this.disableFanOut = options.disableFanOut || false;
4445
}
4546

4647
subscribe(channel) {
@@ -72,9 +73,13 @@ class Subscriber extends events.EventEmitter {
7273
}
7374

7475
_createSubscription(topic, channel) {
75-
76-
const subscriptionUUID = uuid.v1();
77-
var subscriptionName = `${namePrefix}-${channel}-${subscriptionUUID}`;
76+
let subscriptionName;
77+
if (!this.disableFanOut) {
78+
const subscriptionUUID = uuid.v1();
79+
subscriptionName = `${namePrefix}-${channel}-${subscriptionUUID}`;
80+
} else {
81+
subscriptionName = `${namePrefix}-${channel}`;
82+
}
7883

7984
topic.subscribe(subscriptionName, (err, subscription) => {
8085

@@ -140,8 +145,8 @@ function createPublisher() {
140145
return new Publisher(emitter);
141146
}
142147

143-
function createSubscriber() {
144-
return new Subscriber();
148+
function createSubscriber(options) {
149+
return new Subscriber(options);
145150
}
146151

147152
module.exports = {

0 commit comments

Comments
 (0)