Skip to content

Commit 6c3908e

Browse files
author
Michael Oliver
committed
Get tests working
1 parent 0895631 commit 6c3908e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/redis-pubsub.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Cluster, Ok, Redis, RedisOptions} from 'ioredis';
2-
3-
import {PubSubAsyncIterator} from './pubsub-async-iterator';
42
import {PubSubEngine} from 'graphql-subscriptions';
3+
import {PubSubAsyncIterator} from './pubsub-async-iterator';
54

65
type RedisClient = Redis | Cluster;
76
type OnMessage<T> = (message: T) => void;
@@ -93,9 +92,13 @@ export class RedisPubSub implements PubSubEngine {
9392
const id = this.currentSubscriptionId++;
9493
this.subscriptionMap[id] = [triggerName, onMessage];
9594

95+
if (!this.subsRefsMap.has(triggerName)) {
96+
this.subsRefsMap.set(triggerName, new Set());
97+
}
98+
9699
const refs = this.subsRefsMap.get(triggerName);
97-
if (refs?.size > 0) {
98-
refs.add(id)
100+
if (refs.size > 0) {
101+
refs.add(id);
99102
return Promise.resolve(id);
100103
} else {
101104
return new Promise<number>((resolve, reject) => {
@@ -174,10 +177,10 @@ export class RedisPubSub implements PubSubEngine {
174177
parsedMessage = message;
175178
}
176179

177-
for (const subId in subscribers) {
180+
subscribers.forEach(subId => {
178181
const [, listener] = this.subscriptionMap[subId];
179182
listener(parsedMessage);
180-
}
183+
});
181184
}
182185
}
183186

0 commit comments

Comments
 (0)