Skip to content

Commit

Permalink
fix: disallow multiple namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Buzzertech committed Oct 7, 2018
1 parent 731b98e commit 3bf0fee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ let subscriber: any;

export default new class PubSub {
init (Subscriber: any) {
if (typeof Subscriber === undefined) {
if (typeof Subscriber === 'undefined') {
throw new Error ('Please provide a new redis instance for subscribe')
}

subscriber = Subscriber;
}

subscribe(channel: string) {
if (typeof subscriber.subscribe === undefined) {
if (typeof subscriber.subscribe === 'undefined') {
throw new Error('The provided redis client doesn\'t supports subscribing to messages');
}

Expand Down
15 changes: 11 additions & 4 deletions src/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@ export class Queue {
constructor(opts: IQueueOpts) {
this.opts = opts;

if (typeof this.opts.redis === undefined) {
if (typeof this.opts.redis === 'undefined') {
throw new Error('Redis client not provided');
}

if (typeof this.opts.subscriberRedis === undefined) {
throw new Error('Subscriber Redis Client Not provided');
if (typeof this.opts.subscriberRedis === 'undefined') {
throw new Error('Subscriber Redis Client not provided');
}

Pubsub.init(this.opts.subscriberRedis);
}

public registerNamespace(namespace: string, handler: (namespace:string, ctx: any) => any): any {
if (typeof namespace === undefined) {
if (this.namespace && this.namespace.length > 0) {
throw new Error('Cannot change namespace once initialized');
}

if (typeof namespace === 'undefined' || typeof namespace === null) {
throw new Error('Namespace cannot be undefined or null');
}



this.namespace = namespace;
this.registerPollingBooth(this.namespace, handler);
return this;
Expand Down

0 comments on commit 3bf0fee

Please sign in to comment.