Skip to content

Commit 6584a91

Browse files
authored
feat: implement Symbol.dispose (#406)
1 parent 07104b0 commit 6584a91

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

redis.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export interface Redis extends RedisCommands {
112112
): Promise<RedisReply>;
113113
connect(): Promise<void>;
114114
close(): void;
115+
[Symbol.dispose](): void;
115116
}
116117

117118
class RedisImpl implements Redis {
@@ -142,7 +143,11 @@ class RedisImpl implements Redis {
142143
}
143144

144145
close(): void {
145-
this.executor.close();
146+
return this.executor.close();
147+
}
148+
149+
[Symbol.dispose](): void {
150+
return this.close();
146151
}
147152

148153
async execReply<T extends Raw = Raw>(

tests/commands/connection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ export function connectionTests(
143143
client.close();
144144
});
145145
});
146+
147+
describe("using", () => {
148+
it("implements `Symbol.dispose`", async () => {
149+
using client = await connect(getOpts());
150+
assert(client.isConnected);
151+
assert(!client.isClosed);
152+
});
153+
});
146154
}
147155

148156
function parseCommandStats(

0 commit comments

Comments
 (0)