Skip to content

Commit af2eab5

Browse files
committed
fix: correct _remove logic
1 parent 3cc9f34 commit af2eab5

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/bridge.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ type ArrayParameter<T extends readonly any[] = readonly any[]> = Parameter<T | T
6464
type SerializableParameter<T = never> = ArrayParameter | Parameter<any> | ReadonlyArray<SerializableParameter<T>> | Serializable | T | never;
6565

6666
export type BridgetClient = {
67-
end: () => void,
67+
end: () => Promise<void>,
6868
off: (eventName: string, listener: (...args: any[]) => void) => void,
6969
on: (eventName: string, listener: (...args: any[]) => void) => void,
7070
query: (sql: string, parameters: SerializableParameter[]) => Promise<QueryResult>,
71+
release: () => Promise<void>,
7172
};
7273

7374
export const createBridge = (postgres: typeof Postgres) => {
@@ -135,7 +136,7 @@ export const createBridge = (postgres: typeof Postgres) => {
135136
return compatibleConnection;
136137
},
137138
destroy: async (client: BridgetClient) => {
138-
client.end();
139+
await client.end();
139140
},
140141
}, {
141142
max: poolConfiguration.max ?? 10,
@@ -155,8 +156,8 @@ export const createBridge = (postgres: typeof Postgres) => {
155156
// TODO implement logic equivalent to https://github.com/brianc/node-postgres/blob/master/packages/pg-pool/index.js#L109-L152
156157
}
157158

158-
public async _remove (client: {end: () => Promise<void>, }) {
159-
await client.end();
159+
public async _remove (client: BridgetClient) {
160+
await this.pool.destroy(client);
160161

161162
this.poolEvents.emit('remove', client);
162163
}
@@ -190,7 +191,7 @@ export const createBridge = (postgres: typeof Postgres) => {
190191

191192
public async end () {
192193
for (const client of this._clients) {
193-
client.end();
194+
await client.end();
194195
}
195196
}
196197
};

test/postgres-bridge/bridge.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ for (const {
5858
t.true(spy.called);
5959

6060
t.is(spy.firstCall.args[0], connection);
61+
62+
t.is(pool.totalCount, 0);
6163
});
6264

6365
test(clientName + ': "notice event is fired when connection produces a notice"', async (t) => {

0 commit comments

Comments
 (0)