Skip to content

Commit 69cd0b4

Browse files
authored
fix: add close method to Spanner client (#1416)
Adds a close method to the Spanner client that will (try to) clean up the resources it has in use. Towards #1306
1 parent e4fc2a1 commit 69cd0b4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ class Spanner extends GrpcService {
268268
};
269269
}
270270

271+
/** Closes this Spanner client and cleans up all resources used by it. */
272+
close(): void {
273+
this.clients_.forEach(c => {
274+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
275+
const client = c as any;
276+
if (client.operationsClient && client.operationsClient.close) {
277+
client.operationsClient.close();
278+
}
279+
client.close();
280+
});
281+
}
282+
271283
createInstance(
272284
name: string,
273285
config: CreateInstanceRequest

test/spanner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ describe('Spanner with mock server', () => {
147147
});
148148

149149
after(() => {
150+
spanner.close();
150151
server.tryShutdown(() => {});
151152
delete process.env.SPANNER_EMULATOR_HOST;
152153
sandbox.restore();

0 commit comments

Comments
 (0)