Skip to content

Commit

Permalink
feat: Allow using keyword with pool clients
Browse files Browse the repository at this point in the history
  • Loading branch information
langpavel committed Feb 27, 2024
1 parent 5915574 commit 2af3660
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,8 @@ export class PoolClient extends QueryClient {
// Cleanup all session related metadata
this.resetSessionMetadata();
}

[Symbol.dispose]() {
this.release();
}
}
12 changes: 12 additions & 0 deletions tests/pool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}),
);

0 comments on commit 2af3660

Please sign in to comment.