Skip to content

Commit

Permalink
feat: implement Symbol.dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a committed Oct 26, 2023
1 parent 07104b0 commit 7328921
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface Redis extends RedisCommands {
): Promise<RedisReply>;
connect(): Promise<void>;
close(): void;
[Symbol.dispose](): void;
}

class RedisImpl implements Redis {
Expand Down Expand Up @@ -142,7 +143,11 @@ class RedisImpl implements Redis {
}

close(): void {
this.executor.close();
return this.executor.close();
}

[Symbol.dispose](): void {
return this.close();
}

async execReply<T extends Raw = Raw>(
Expand Down
8 changes: 8 additions & 0 deletions tests/commands/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ export function connectionTests(
client.close();
});
});

describe("using", () => {
it("implements `Symbol.dispose`", async () => {
using client = await connect(getOpts());
assert(client.isConnected);
assert(!client.isClosed);
});
});
}

function parseCommandStats(
Expand Down

0 comments on commit 7328921

Please sign in to comment.