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); }