Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export class Bus {
await this.processErrorRetryQueue()
}

subscribe<T extends Serializable>(channel: string, handler: SubscribeHandler<T>) {
async subscribe<T extends Serializable>(channel: string, handler: SubscribeHandler<T>) {
debug(`subscribing to channel ${channel}`)

return this.#transport.subscribe(channel, async (message) => {
return await this.#transport.subscribe(channel, async (message) => {
debug('received message %j from bus', message)
// @ts-expect-error - TODO: Weird typing issue
handler(message)
Expand Down Expand Up @@ -94,7 +94,7 @@ export class Bus {
return this.#transport.disconnect()
}

unsubscribe(channel: string) {
return this.#transport.unsubscribe(channel)
async unsubscribe(channel: string) {
return await this.#transport.unsubscribe(channel)
}
}
8 changes: 4 additions & 4 deletions src/bus_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export class BusManager<KnownTransports extends Record<string, TransportConfig>>
return this.use().publish(channel, message)
}

subscribe<T extends Serializable>(channel: string, handler: SubscribeHandler<T>) {
return this.use().subscribe(channel, handler)
async subscribe<T extends Serializable>(channel: string, handler: SubscribeHandler<T>) {
return await this.use().subscribe(channel, handler)
}

unsubscribe(channel: string) {
return this.use().unsubscribe(channel)
async unsubscribe(channel: string) {
return await this.use().unsubscribe(channel)
}

disconnect() {
Expand Down
6 changes: 1 addition & 5 deletions src/transports/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ export class RedisTransport implements Transport {
channel: string,
handler: SubscribeHandler<T>
): Promise<void> {
this.#subscriber.subscribe(channel, (err) => {
if (err) {
throw err
}
})
await this.#subscriber.subscribe(channel)

const event = this.#useMessageBuffer ? 'messageBuffer' : 'message'
this.#subscriber.on(event, (receivedChannel: Buffer | string, message: Buffer | string) => {
Expand Down
4 changes: 2 additions & 2 deletions test_helpers/chaos_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class ChaosTransport implements Transport {
return this.#innerTransport.subscribe(channel, handler)
}

unsubscribe(channel: string) {
return this.#innerTransport.unsubscribe(channel)
async unsubscribe(channel: string) {
return await this.#innerTransport.unsubscribe(channel)
}

disconnect() {
Expand Down