Skip to content

Commit 45ac3f9

Browse files
committed
refactor: 将_close方法改为可选并直接调用
移除对Reflect.get的使用,直接检查并调用_close方法
1 parent e1477df commit 45ac3f9

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export abstract class Base<T = any, O extends BaseOptions<T> = BaseOptions<T>> e
1717
options: O;
1818
#closed = false;
1919
#localStorage: AsyncLocalStorage<T>;
20-
/* @ts-expect-error just a placeholder, will be implemented in subclass */
21-
protected _close(): Promise<void>;
20+
/* just a method signature, will be implemented in subclass */
21+
protected _close?(): Promise<void>;
2222
constructor(options?: O) {
2323
super();
2424

@@ -100,13 +100,12 @@ export abstract class Base<T = any, O extends BaseOptions<T> = BaseOptions<T>> e
100100
return;
101101
}
102102
this.#closed = true;
103-
const closeMethod = Reflect.get(this, '_close') as () => Promise<void>;
104-
if (typeof closeMethod !== 'function') {
103+
if (typeof this._close !== 'function') {
105104
return;
106105
}
107106

108107
try {
109-
await closeMethod.apply(this);
108+
await this._close();
110109
} catch (err) {
111110
this.emit('error', err);
112111
}

0 commit comments

Comments
 (0)