From 8b19699fd6327a762d0afbd6d0cf6041f68c3712 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 19 Dec 2024 20:23:57 +1100 Subject: [PATCH] fix: remove leaky `readLines()` and `readReply()` functions (#188) --- mod.ts | 18 ++---------------- test.ts | 18 ++++++------------ 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/mod.ts b/mod.ts index 00505ac..b282107 100644 --- a/mod.ts +++ b/mod.ts @@ -92,14 +92,7 @@ async function writeCommand( const DELIM_LPS = new Uint8Array([0, 0]); -/** - * Reads and processes the response line-by-line. Exported for testing. - * - * @private - */ -export async function* readLines( - reader: Reader, -): AsyncIterableIterator { +async function* readLines(reader: Reader): AsyncIterableIterator { let chunks = new Uint8Array(); // Modified KMP @@ -148,14 +141,7 @@ function readNReplies( return Array.fromAsync({ length }, () => readReply(iterator, raw)); } -/** - * Reads and processes the response reply-by-reply. Exported for testing. - * - * @see {@link https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md} - * - * @private - */ -export async function readReply( +async function readReply( iterator: AsyncIterableIterator, raw = false, ): Promise { diff --git a/test.ts b/test.ts index 75c724f..ebffae2 100644 --- a/test.ts +++ b/test.ts @@ -1,25 +1,19 @@ import { assertEquals, assertRejects } from "@std/assert"; import { Buffer } from "@std/io/buffer"; -import { - type Command, - readLines, - readReply, - RedisClient, - type Reply, -} from "./mod.ts"; +import { type Command, RedisClient, type Reply } from "./mod.ts"; const encoder = new TextEncoder(); async function readReplyTest(output: string, expected: Reply) { - assertEquals( - await readReply(readLines(new Buffer(encoder.encode(output)))), - expected, - ); + const redisClient = new RedisClient(new Buffer(encoder.encode(output))); + const { value } = await redisClient.readReplies().next(); + assertEquals(value, expected); } function readReplyRejectTest(output: string, expected: string) { + const redisClient = new RedisClient(new Buffer(encoder.encode(output))); return assertRejects( - () => readReply(readLines(new Buffer(encoder.encode(output)))), + () => redisClient.readReplies().next(), expected, ); }