Skip to content

Commit

Permalink
Set to undefined before closing
Browse files Browse the repository at this point in the history
  • Loading branch information
ejscribner committed Sep 2, 2024
1 parent 3bd30d7 commit c8b202d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ottoman/ottoman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { fields: string[]; modelName: string }> = {};
Expand Down Expand Up @@ -376,13 +376,15 @@ export class Ottoman {
* connection.close().then(() => console.log('connection closed'));
* ```
*/
async close(): Promise<void> {
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();
}
}

Expand Down

0 comments on commit c8b202d

Please sign in to comment.