From 74f3605929a61e21a5ecfecd593ed87001a28c79 Mon Sep 17 00:00:00 2001 From: hzgotb Date: Mon, 23 Dec 2024 18:03:19 +0800 Subject: [PATCH] make sure close behavior correct --- src/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2761c45..b609338 100644 --- a/src/index.ts +++ b/src/index.ts @@ -98,14 +98,17 @@ export abstract class Base extends ReadyEventEmitter { if (this.#closed) { return; } - this.#closed = true; - const closeMethod = Reflect.get(this, '_close') as () => Promise; + const closeMethod = Reflect.get(this, '_close'); + if (typeof closeMethod !== 'function') { + this.#closed = true; return; } try { - await closeMethod.apply(this); + const result = await closeMethod.apply(this); + this.#closed = true; + return result; } catch (err) { this.emit('error', err); }