diff --git a/io.ts b/io.ts index 41676e5d..97c43792 100644 --- a/io.ts +++ b/io.ts @@ -42,7 +42,7 @@ export function createRequest( export async function sendCommand( writer: BufWriter, reader: BufReader, - command, + command: string, ...args ): Promise { const msg = createRequest(command, ...args); diff --git a/pubsub.ts b/pubsub.ts index 887457ba..d720231f 100644 --- a/pubsub.ts +++ b/pubsub.ts @@ -1,5 +1,5 @@ import { BufReader, BufWriter } from "https://deno.land/std@v0.7.0/io/bufio.ts"; -import { readArrayReply, sendCommand } from "./io.ts"; +import { createRequest, readArrayReply, sendCommand } from "./io.ts"; export type RedisSubscription = { readonly isClosed: boolean; @@ -77,9 +77,7 @@ class RedisSubscriptionImpl implements RedisSubscription { async close() { try { - console.log("unsubscribing"); await this.unsubscribe(...Object.keys(this.channels)); - console.log("unsubscribing done"); await this.punsubscribe(...Object.keys(this.patterns)); } finally { this._isClosed = true; diff --git a/pubsub_test.ts b/pubsub_test.ts index 734c18dc..5d207c9a 100644 --- a/pubsub_test.ts +++ b/pubsub_test.ts @@ -26,16 +26,17 @@ test(async function testSubscribe2() { const pub = await connect(addr); const sub = await redis.subscribe("subsc2"); let message: RedisPubSubMessage; - (async function() { + const p = (async function() { const it = sub.receive(); message = (await it.next()).value; })(); await pub.publish("subsc2", "wayway"); - await sub.close(); + await p; assertEquals(message, { channel: "subsc2", message: "wayway" }); + await sub.close(); const a = await redis.get("aaa"); assertEquals(a, void 0); pub.close(); @@ -48,14 +49,14 @@ test(async function testPsubscribe() { const sub = await redis.psubscribe("ps*"); let message1; let message2; - (async function() { - const it = sub.receive(); + const it = sub.receive(); + const p = (async function() { message1 = (await it.next()).value; message2 = (await it.next()).value; })(); await pub.publish("psub", "wayway"); await pub.publish("psubs", "heyhey"); - await sub.close(); + await p; assertEquals(message1, { pattern: "ps*", channel: "psub", @@ -66,6 +67,7 @@ test(async function testPsubscribe() { channel: "psubs", message: "heyhey" }); + await sub.close(); pub.close(); redis.close(); });