Skip to content

Commit

Permalink
make sure close behavior correct
Browse files Browse the repository at this point in the history
  • Loading branch information
hzgotb committed Dec 23, 2024
1 parent 6f03438 commit 74f3605
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,17 @@ export abstract class Base<T = any> extends ReadyEventEmitter {
if (this.#closed) {
return;
}
this.#closed = true;
const closeMethod = Reflect.get(this, '_close') as () => Promise<void>;
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);
}
Expand Down

0 comments on commit 74f3605

Please sign in to comment.