Skip to content

Commit

Permalink
Reset state immediately after unplugging
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos authored May 28, 2021
1 parent 9ad60b7 commit 552c243
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/plug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,12 @@ export class GlobalPlug implements Plug {
return;
}

const {instance, plugins} = this;

const logger = this.sdk.getLogger();
const pending: Promise<void>[] = [];

for (const [pluginName, controller] of Object.entries(this.plugins)) {
for (const [pluginName, controller] of Object.entries(plugins)) {
if (typeof controller.disable !== 'function') {
continue;
}
Expand All @@ -358,18 +360,19 @@ export class GlobalPlug implements Plug {
);
}

// Reset
delete this.instance;

this.plugins = {};
this.ready = new Promise(resolve => {
this.initialize = resolve;
});

await Promise.all(pending);

try {
await this.instance.close();
await instance.close();
} finally {
delete this.instance;

this.plugins = {};
this.ready = new Promise(resolve => {
this.initialize = resolve;
});

logger.info('🔌 Croct has been unplugged.');
}
}
Expand Down

0 comments on commit 552c243

Please sign in to comment.