From 552c243785205a3cbcb834d98d625080a0c51c9f Mon Sep 17 00:00:00 2001 From: Marcos Passos Date: Fri, 28 May 2021 18:52:12 -0300 Subject: [PATCH] Reset state immediately after unplugging --- src/plug.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/plug.ts b/src/plug.ts index 8062eb87..bbce8df3 100644 --- a/src/plug.ts +++ b/src/plug.ts @@ -333,10 +333,12 @@ export class GlobalPlug implements Plug { return; } + const {instance, plugins} = this; + const logger = this.sdk.getLogger(); const pending: Promise[] = []; - for (const [pluginName, controller] of Object.entries(this.plugins)) { + for (const [pluginName, controller] of Object.entries(plugins)) { if (typeof controller.disable !== 'function') { continue; } @@ -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.'); } }