From c8b202d21268bdec9b9ad5f8e189708ef48de714 Mon Sep 17 00:00:00 2001 From: Elliot Scribner Date: Mon, 2 Sep 2024 10:14:05 -0700 Subject: [PATCH] Set to undefined before closing --- src/ottoman/ottoman.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ottoman/ottoman.ts b/src/ottoman/ottoman.ts index 2a591153..53ce276e 100644 --- a/src/ottoman/ottoman.ts +++ b/src/ottoman/ottoman.ts @@ -76,7 +76,7 @@ export type OttomanEvents = 'IndexOnline'; * Store default connection. */ export let __ottoman: Ottoman; -export let __ottomanInstances: Ottoman[] = []; +export const __ottomanInstances: Ottoman[] = []; export class Ottoman { private n1qlIndexes: Record = {}; @@ -376,13 +376,15 @@ export class Ottoman { * connection.close().then(() => console.log('connection closed')); * ``` */ - async close(): Promise { + async close() { + console.log('Closing: ', this.id, exports.__ottoman ? exports.__ottoman.id : '____'); if (this.cluster) { - await this.cluster.close(); - __ottomanInstances = __ottomanInstances.filter((instance) => instance.id !== this.id); - if (__ottoman?.id === this.id) { - (__ottoman as any) = undefined; + exports.__ottomanInstances = exports.__ottomanInstances.filter((instance) => instance.id !== this.id); + if (exports.__ottoman?.id === this.id) { + console.log(exports.__ottoman.id, '__ottoman -> undefined'); + exports.__ottoman = undefined; } + await this.cluster.close(); } }