From 2af36604b083a6b79ccee2fe9b50a813a7e6314a Mon Sep 17 00:00:00 2001 From: Pavel Lang Date: Tue, 27 Feb 2024 15:53:52 +0100 Subject: [PATCH] feat: Allow `using` keyword with pool clients --- client.ts | 4 ++++ tests/pool_test.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/client.ts b/client.ts index 7635c6a3..d254188d 100644 --- a/client.ts +++ b/client.ts @@ -515,4 +515,8 @@ export class PoolClient extends QueryClient { // Cleanup all session related metadata this.resetSessionMetadata(); } + + [Symbol.dispose]() { + this.release(); + } } diff --git a/tests/pool_test.ts b/tests/pool_test.ts index fb7c3fcb..2f481c5f 100644 --- a/tests/pool_test.ts +++ b/tests/pool_test.ts @@ -140,3 +140,15 @@ Deno.test( ); }), ); + +Deno.test( + "Pool client will be released after `using` block", + testPool(async (POOL, size) => { + const initialPoolAvailable = POOL.available; + { + using client = await POOL.connect(); + assertEquals(POOL.available, initialPoolAvailable - 1); + } + assertEquals(POOL.available, initialPoolAvailable); + }), +);