@gby/destroyable 3.6.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Destroyable.d.ts +4 -0
- package/dist/Destroyable.d.ts.map +1 -1
- package/dist/DestroyableEventEmitter.d.ts +2 -2
- package/dist/DestroyableEventEmitter.d.ts.map +1 -1
- package/dist/{DestroyableEventTarget-DdEIvJNx.js → DestroyableEventTarget-CIMBV0bD.js} +134 -145
- package/dist/DestroyableEventTarget-uZtYhcb1.cjs +1 -0
- package/dist/createDestroyableSubClass.d.ts +2 -2
- package/dist/index-web.cjs +1 -1
- package/dist/index-web.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +31 -37
- package/package.json +4 -4
- package/dist/DestroyableEventTarget-D6QEuQ_5.cjs +0 -1
package/dist/Destroyable.d.ts
CHANGED
|
@@ -83,12 +83,16 @@ export declare class Destroyable implements IDestroyable {
|
|
|
83
83
|
export declare function throwOnDestroyed(): void;
|
|
84
84
|
/**
|
|
85
85
|
* 销毁对象
|
|
86
|
+
* @remarks
|
|
87
|
+
* 会将所有的方法都替换为抛出已销毁错误的函数
|
|
86
88
|
* @param object
|
|
87
89
|
* @returns
|
|
88
90
|
*/
|
|
89
91
|
export declare function destroyObject(object: any): boolean;
|
|
90
92
|
/**
|
|
91
93
|
* 销毁 Destroyable 对象
|
|
94
|
+
* @remarks
|
|
95
|
+
* 会将所有非 Destroyable.prototype 的方法都替换为抛出已销毁错误的函数
|
|
92
96
|
* @param object
|
|
93
97
|
* @returns
|
|
94
98
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Destroyable.d.ts","sourceRoot":"","sources":["../src/Destroyable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAMzD;;GAEG;AACH,qBAAa,WAAY,YAAW,YAAY;IAE5C;;;;OAIG;IACH,QAAQ,S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EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAapE;;;;OAIG;IACH,WAAW,IAAI,GAAG;IAKlB;;;;OAIG;IACH,WAAW;IA6BX;;;;;OAKG;IACH,OAAO;CAuBV;AAKD;;GAEG;AACH,wBAAgB,gBAAgB,SAE/B;AAKD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,WASxC;AAKD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,WAYtD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { FunDestroyer, IDestroyable } from "./type";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
|
-
export type EventMap<T> = Record<keyof T, any[]
|
|
3
|
+
export type EventMap<T> = Record<keyof T, any[]>;
|
|
4
4
|
export type DefaultEventMap = [never];
|
|
5
5
|
/**
|
|
6
6
|
* 可销毁的对象,继承自 Node 的 EventEmitter
|
|
7
7
|
*/
|
|
8
|
-
export declare class DestroyableEventEmitter<EM extends EventMap<EM> =
|
|
8
|
+
export declare class DestroyableEventEmitter<EM extends EventMap<EM> = any> extends EventEmitter<EM> implements IDestroyable {
|
|
9
9
|
/**
|
|
10
10
|
* 引用计数
|
|
11
11
|
* @remarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DestroyableEventEmitter.d.ts","sourceRoot":"","sources":["../src/DestroyableEventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"DestroyableEventEmitter.d.ts","sourceRoot":"","sources":["../src/DestroyableEventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE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OAAO,GAAG,CAAC;IAStF,aAAa,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAChD,aAAa,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAChD,aAAa,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAgBpE;;;;OAIG;IACH,WAAW,IAAI,GAAG;IAKlB;;;;OAIG;IACH,WAAW;IA6BX;;;;;OAKG;IACH,OAAO;CAwBV"}
|
|
@@ -1,50 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @remarks
|
|
11
|
-
* 引用计数为 0 时,对象才会被销毁
|
|
12
|
-
*/
|
|
13
|
-
n(this, "refCount", 0);
|
|
14
|
-
n(this, "_isDestroyed", !1);
|
|
15
|
-
/**
|
|
16
|
-
* 销毁者
|
|
17
|
-
*/
|
|
18
|
-
n(this, "_destroyers", []);
|
|
19
|
-
}
|
|
1
|
+
import { serialCallAllFuns as h } from "com-tools";
|
|
2
|
+
import { EventBus as u } from "@gby/event-bus";
|
|
3
|
+
class c {
|
|
4
|
+
/**
|
|
5
|
+
* 引用计数
|
|
6
|
+
* @remarks
|
|
7
|
+
* 引用计数为 0 时,对象才会被销毁
|
|
8
|
+
*/
|
|
9
|
+
refCount = 0;
|
|
20
10
|
/**
|
|
21
11
|
* 是否已经销毁
|
|
22
12
|
*/
|
|
23
13
|
get isDestroyed() {
|
|
24
14
|
return this._isDestroyed;
|
|
25
15
|
}
|
|
16
|
+
_isDestroyed = !1;
|
|
26
17
|
/**
|
|
27
18
|
* 是否可以销毁
|
|
28
19
|
*/
|
|
29
20
|
get canDestroy() {
|
|
30
21
|
return !this.isDestroyed && this.refCount <= 0;
|
|
31
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 销毁者
|
|
25
|
+
*/
|
|
26
|
+
_destroyers = [];
|
|
32
27
|
/**
|
|
33
28
|
* 添加销毁者
|
|
34
29
|
* @param fun
|
|
35
30
|
* @returns 返回销毁者的顺序
|
|
36
31
|
*/
|
|
37
|
-
disposeFun(
|
|
38
|
-
return this._destroyers.push(
|
|
32
|
+
disposeFun(e) {
|
|
33
|
+
return this._destroyers.push(e), e;
|
|
39
34
|
}
|
|
40
35
|
/**
|
|
41
36
|
* 取消销毁者函数
|
|
42
37
|
* @param fun
|
|
43
38
|
* @returns
|
|
44
39
|
*/
|
|
45
|
-
cancelDisposeFun(
|
|
46
|
-
const
|
|
47
|
-
return this._destroyers.splice(
|
|
40
|
+
cancelDisposeFun(e) {
|
|
41
|
+
const t = this._destroyers.indexOf(e);
|
|
42
|
+
return this._destroyers.splice(t, 1), e;
|
|
48
43
|
}
|
|
49
44
|
/**
|
|
50
45
|
* 添加销毁对象
|
|
@@ -52,28 +47,28 @@ class p {
|
|
|
52
47
|
* @param sync - 表示是否使用 `obj.destroySync()` 方法进行销毁;默认使用 `obj.destroy()` 方法进行销毁
|
|
53
48
|
* @returns
|
|
54
49
|
*/
|
|
55
|
-
disposeObj(
|
|
56
|
-
const
|
|
57
|
-
return
|
|
50
|
+
disposeObj(e, t) {
|
|
51
|
+
const s = t ? function() {
|
|
52
|
+
return e.destroySync();
|
|
58
53
|
} : function() {
|
|
59
|
-
return
|
|
54
|
+
return e.destroy();
|
|
60
55
|
};
|
|
61
|
-
return this.disposeFun(
|
|
56
|
+
return this.disposeFun(s), e.__destroyable_destroyer = s, e;
|
|
62
57
|
}
|
|
63
58
|
/**
|
|
64
59
|
* 取消销毁者函数
|
|
65
60
|
* @param fun
|
|
66
61
|
* @returns
|
|
67
62
|
*/
|
|
68
|
-
cancelDisposeObj(
|
|
69
|
-
const
|
|
70
|
-
return
|
|
63
|
+
cancelDisposeObj(e) {
|
|
64
|
+
const t = e.__destroyable_destroyer;
|
|
65
|
+
return t && this.cancelDisposeFun(t), e;
|
|
71
66
|
}
|
|
72
|
-
dispose(
|
|
73
|
-
return typeof
|
|
67
|
+
dispose(e, t) {
|
|
68
|
+
return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, t);
|
|
74
69
|
}
|
|
75
|
-
cancelDispose(
|
|
76
|
-
return typeof
|
|
70
|
+
cancelDispose(e) {
|
|
71
|
+
return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
|
|
77
72
|
}
|
|
78
73
|
/**
|
|
79
74
|
* 自己的销毁方法
|
|
@@ -89,22 +84,22 @@ class p {
|
|
|
89
84
|
*/
|
|
90
85
|
destroySync() {
|
|
91
86
|
if (!this.canDestroy) return this.isDestroyed;
|
|
92
|
-
let
|
|
93
|
-
for (; --
|
|
94
|
-
const
|
|
87
|
+
let e = this._destroyers.length;
|
|
88
|
+
for (; --e >= 0; ) {
|
|
89
|
+
const t = this._destroyers[e];
|
|
95
90
|
try {
|
|
96
|
-
|
|
97
|
-
} catch (
|
|
98
|
-
console.error("销毁函数在同步销毁时出错", this,
|
|
91
|
+
t();
|
|
92
|
+
} catch (s) {
|
|
93
|
+
console.error("销毁函数在同步销毁时出错", this, t, s);
|
|
99
94
|
}
|
|
100
95
|
}
|
|
101
96
|
this._destroyers.length = 0;
|
|
102
97
|
try {
|
|
103
98
|
this.destroyThis();
|
|
104
|
-
} catch (
|
|
105
|
-
console.error("destroyThis 在异步销毁时出错", this,
|
|
99
|
+
} catch (t) {
|
|
100
|
+
console.error("destroyThis 在异步销毁时出错", this, t);
|
|
106
101
|
}
|
|
107
|
-
return
|
|
102
|
+
return o(this), !0;
|
|
108
103
|
}
|
|
109
104
|
/**
|
|
110
105
|
* 串行销毁
|
|
@@ -114,71 +109,68 @@ class p {
|
|
|
114
109
|
*/
|
|
115
110
|
destroy() {
|
|
116
111
|
if (!this.canDestroy) return this.isDestroyed;
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
console.error("销毁函数在串行销毁时出错", this,
|
|
112
|
+
const e = this._destroyers.toReversed();
|
|
113
|
+
e.push(this.destroyThis), this._destroyers.length = 0;
|
|
114
|
+
const t = h(e, this, null, (s, r) => {
|
|
115
|
+
console.error("销毁函数在串行销毁时出错", this, r, s);
|
|
121
116
|
});
|
|
122
|
-
return
|
|
117
|
+
return t instanceof Promise ? t.then(() => (o(this), !0)) : (o(this), !0);
|
|
123
118
|
}
|
|
124
119
|
}
|
|
125
|
-
function
|
|
120
|
+
function d() {
|
|
126
121
|
throw "已销毁";
|
|
127
122
|
}
|
|
128
|
-
function
|
|
129
|
-
for (var
|
|
130
|
-
typeof i[
|
|
123
|
+
function f(i) {
|
|
124
|
+
for (var e in i)
|
|
125
|
+
typeof i[e] == "function" && (i[e] = d);
|
|
131
126
|
return i._isDestroyed = !0, !0;
|
|
132
127
|
}
|
|
133
|
-
function
|
|
134
|
-
for (var
|
|
135
|
-
!(
|
|
128
|
+
function o(i) {
|
|
129
|
+
for (var e in i)
|
|
130
|
+
!(e in c.prototype) && typeof i[e] == "function" && (i[e] = d);
|
|
136
131
|
return i._isDestroyed = !0, !0;
|
|
137
132
|
}
|
|
138
|
-
function
|
|
139
|
-
class
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
*/
|
|
147
|
-
n(this, "refCount", 0);
|
|
148
|
-
n(this, "_isDestroyed", !1);
|
|
149
|
-
/**
|
|
150
|
-
* 销毁者
|
|
151
|
-
*/
|
|
152
|
-
n(this, "_destroyers", []);
|
|
153
|
-
}
|
|
133
|
+
function p(i) {
|
|
134
|
+
class e extends i {
|
|
135
|
+
/**
|
|
136
|
+
* 引用计数
|
|
137
|
+
* @remarks
|
|
138
|
+
* 引用计数为 0 时,对象才会被销毁
|
|
139
|
+
*/
|
|
140
|
+
refCount = 0;
|
|
154
141
|
/**
|
|
155
142
|
* 是否已经销毁
|
|
156
143
|
*/
|
|
157
144
|
get isDestroyed() {
|
|
158
145
|
return this._isDestroyed;
|
|
159
146
|
}
|
|
147
|
+
_isDestroyed = !1;
|
|
160
148
|
/**
|
|
161
149
|
* 是否可以销毁
|
|
162
150
|
*/
|
|
163
151
|
get canDestroy() {
|
|
164
152
|
return !this.isDestroyed && this.refCount <= 0;
|
|
165
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* 销毁者
|
|
156
|
+
*/
|
|
157
|
+
_destroyers = [];
|
|
166
158
|
/**
|
|
167
159
|
* 添加销毁者
|
|
168
160
|
* @param fun
|
|
169
161
|
* @returns 返回销毁者的顺序
|
|
170
162
|
*/
|
|
171
|
-
disposeFun(
|
|
172
|
-
return this._destroyers.push(
|
|
163
|
+
disposeFun(s) {
|
|
164
|
+
return this._destroyers.push(s), s;
|
|
173
165
|
}
|
|
174
166
|
/**
|
|
175
167
|
* 取消销毁者函数
|
|
176
168
|
* @param fun
|
|
177
169
|
* @returns
|
|
178
170
|
*/
|
|
179
|
-
cancelDisposeFun(
|
|
180
|
-
const
|
|
181
|
-
return this._destroyers.splice(
|
|
171
|
+
cancelDisposeFun(s) {
|
|
172
|
+
const r = this._destroyers.indexOf(s);
|
|
173
|
+
return this._destroyers.splice(r, 1), s;
|
|
182
174
|
}
|
|
183
175
|
/**
|
|
184
176
|
* 添加销毁对象
|
|
@@ -186,28 +178,28 @@ function x(i) {
|
|
|
186
178
|
* @param sync - 表示是否使用 `obj.destroySync()` 方法进行销毁;默认使用 `obj.destroy()` 方法进行销毁
|
|
187
179
|
* @returns
|
|
188
180
|
*/
|
|
189
|
-
disposeObj(
|
|
190
|
-
const
|
|
191
|
-
return
|
|
181
|
+
disposeObj(s, r) {
|
|
182
|
+
const n = r ? function() {
|
|
183
|
+
return s.destroySync();
|
|
192
184
|
} : function() {
|
|
193
|
-
return
|
|
185
|
+
return s.destroy();
|
|
194
186
|
};
|
|
195
|
-
return this.disposeFun(
|
|
187
|
+
return this.disposeFun(n), s.__destroyable_destroyer = n, s;
|
|
196
188
|
}
|
|
197
189
|
/**
|
|
198
190
|
* 取消销毁者函数
|
|
199
191
|
* @param fun
|
|
200
192
|
* @returns
|
|
201
193
|
*/
|
|
202
|
-
cancelDisposeObj(
|
|
203
|
-
const
|
|
204
|
-
return
|
|
194
|
+
cancelDisposeObj(s) {
|
|
195
|
+
const r = s.__destroyable_destroyer;
|
|
196
|
+
return r && this.cancelDisposeFun(r), s;
|
|
205
197
|
}
|
|
206
|
-
dispose(
|
|
207
|
-
return typeof
|
|
198
|
+
dispose(s, r) {
|
|
199
|
+
return typeof s == "function" ? this.disposeFun(s) : this.disposeObj(s, r);
|
|
208
200
|
}
|
|
209
|
-
cancelDispose(
|
|
210
|
-
return typeof
|
|
201
|
+
cancelDispose(s) {
|
|
202
|
+
return typeof s == "function" ? this.cancelDisposeFun(s) : this.cancelDisposeObj(s);
|
|
211
203
|
}
|
|
212
204
|
/**
|
|
213
205
|
* 自己的销毁方法
|
|
@@ -223,22 +215,22 @@ function x(i) {
|
|
|
223
215
|
*/
|
|
224
216
|
destroySync() {
|
|
225
217
|
if (!this.canDestroy) return this.isDestroyed;
|
|
226
|
-
let
|
|
227
|
-
for (; --
|
|
228
|
-
const
|
|
218
|
+
let s = this._destroyers.length;
|
|
219
|
+
for (; --s >= 0; ) {
|
|
220
|
+
const r = this._destroyers[s];
|
|
229
221
|
try {
|
|
230
|
-
|
|
231
|
-
} catch (
|
|
232
|
-
console.error("销毁函数在同步销毁时出错", this,
|
|
222
|
+
r();
|
|
223
|
+
} catch (n) {
|
|
224
|
+
console.error("销毁函数在同步销毁时出错", this, r, n);
|
|
233
225
|
}
|
|
234
226
|
}
|
|
235
227
|
this._destroyers.length = 0;
|
|
236
228
|
try {
|
|
237
229
|
this.destroyThis();
|
|
238
|
-
} catch (
|
|
239
|
-
console.error("destroyThis 在异步销毁时出错", this,
|
|
230
|
+
} catch (r) {
|
|
231
|
+
console.error("destroyThis 在异步销毁时出错", this, r);
|
|
240
232
|
}
|
|
241
|
-
return
|
|
233
|
+
return o(this), !0;
|
|
242
234
|
}
|
|
243
235
|
/**
|
|
244
236
|
* 串行销毁
|
|
@@ -248,43 +240,40 @@ function x(i) {
|
|
|
248
240
|
*/
|
|
249
241
|
destroy() {
|
|
250
242
|
if (!this.canDestroy) return this.isDestroyed;
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
console.error("销毁函数在串行销毁时出错", this,
|
|
243
|
+
const s = this._destroyers.toReversed();
|
|
244
|
+
s.push(this.destroyThis), this._destroyers.length = 0;
|
|
245
|
+
const r = h(s, this, null, (n, y) => {
|
|
246
|
+
console.error("销毁函数在串行销毁时出错", this, y, n);
|
|
255
247
|
});
|
|
256
|
-
return
|
|
248
|
+
return r instanceof Promise ? r.then(() => (o(this), !0)) : (o(this), !0);
|
|
257
249
|
}
|
|
258
250
|
}
|
|
259
|
-
return
|
|
251
|
+
return e;
|
|
260
252
|
}
|
|
261
|
-
class
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
*/
|
|
269
|
-
n(this, "refCount", 0);
|
|
270
|
-
n(this, "_isDestroyed", !1);
|
|
271
|
-
/**
|
|
272
|
-
* 销毁者
|
|
273
|
-
*/
|
|
274
|
-
n(this, "_destroyers", []);
|
|
275
|
-
}
|
|
253
|
+
class D extends u {
|
|
254
|
+
/**
|
|
255
|
+
* 引用计数
|
|
256
|
+
* @remarks
|
|
257
|
+
* 引用计数为 0 时,对象才会被销毁
|
|
258
|
+
*/
|
|
259
|
+
refCount = 0;
|
|
276
260
|
/**
|
|
277
261
|
* 是否已经销毁
|
|
278
262
|
*/
|
|
279
263
|
get isDestroyed() {
|
|
280
264
|
return this._isDestroyed;
|
|
281
265
|
}
|
|
266
|
+
_isDestroyed = !1;
|
|
282
267
|
/**
|
|
283
268
|
* 是否可以销毁
|
|
284
269
|
*/
|
|
285
270
|
get canDestroy() {
|
|
286
271
|
return !this.isDestroyed && this.refCount <= 0;
|
|
287
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* 销毁者
|
|
275
|
+
*/
|
|
276
|
+
_destroyers = [];
|
|
288
277
|
/**
|
|
289
278
|
* 添加销毁者
|
|
290
279
|
* @param fun
|
|
@@ -299,8 +288,8 @@ class C extends f {
|
|
|
299
288
|
* @returns
|
|
300
289
|
*/
|
|
301
290
|
cancelDisposeFun(e) {
|
|
302
|
-
const
|
|
303
|
-
return this._destroyers.splice(
|
|
291
|
+
const t = this._destroyers.indexOf(e);
|
|
292
|
+
return this._destroyers.splice(t, 1), e;
|
|
304
293
|
}
|
|
305
294
|
/**
|
|
306
295
|
* 添加销毁对象
|
|
@@ -308,13 +297,13 @@ class C extends f {
|
|
|
308
297
|
* @param sync - 表示是否使用 `obj.destroySync()` 方法进行销毁;默认使用 `obj.destroy()` 方法进行销毁
|
|
309
298
|
* @returns
|
|
310
299
|
*/
|
|
311
|
-
disposeObj(e,
|
|
312
|
-
const
|
|
300
|
+
disposeObj(e, t) {
|
|
301
|
+
const s = t ? function() {
|
|
313
302
|
return e.destroySync();
|
|
314
303
|
} : function() {
|
|
315
304
|
return e.destroy();
|
|
316
305
|
};
|
|
317
|
-
return this.disposeFun(
|
|
306
|
+
return this.disposeFun(s), e.__destroyable_destroyer = s, e;
|
|
318
307
|
}
|
|
319
308
|
/**
|
|
320
309
|
* 取消销毁者函数
|
|
@@ -322,11 +311,11 @@ class C extends f {
|
|
|
322
311
|
* @returns
|
|
323
312
|
*/
|
|
324
313
|
cancelDisposeObj(e) {
|
|
325
|
-
const
|
|
326
|
-
return
|
|
314
|
+
const t = e.__destroyable_destroyer;
|
|
315
|
+
return t && this.cancelDisposeFun(t), e;
|
|
327
316
|
}
|
|
328
|
-
dispose(e,
|
|
329
|
-
return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e,
|
|
317
|
+
dispose(e, t) {
|
|
318
|
+
return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, t);
|
|
330
319
|
}
|
|
331
320
|
cancelDispose(e) {
|
|
332
321
|
return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
|
|
@@ -347,20 +336,20 @@ class C extends f {
|
|
|
347
336
|
if (!this.canDestroy) return this.isDestroyed;
|
|
348
337
|
let e = this._destroyers.length;
|
|
349
338
|
for (; --e >= 0; ) {
|
|
350
|
-
const
|
|
339
|
+
const t = this._destroyers[e];
|
|
351
340
|
try {
|
|
352
|
-
|
|
353
|
-
} catch (
|
|
354
|
-
console.error("销毁函数在同步销毁时出错", this,
|
|
341
|
+
t();
|
|
342
|
+
} catch (s) {
|
|
343
|
+
console.error("销毁函数在同步销毁时出错", this, t, s);
|
|
355
344
|
}
|
|
356
345
|
}
|
|
357
346
|
this._destroyers.length = 0;
|
|
358
347
|
try {
|
|
359
348
|
this.destroyThis();
|
|
360
|
-
} catch (
|
|
361
|
-
console.error("destroyThis 在异步销毁时出错", this,
|
|
349
|
+
} catch (t) {
|
|
350
|
+
console.error("destroyThis 在异步销毁时出错", this, t);
|
|
362
351
|
}
|
|
363
|
-
return
|
|
352
|
+
return o(this), !0;
|
|
364
353
|
}
|
|
365
354
|
/**
|
|
366
355
|
* 串行销毁
|
|
@@ -372,17 +361,17 @@ class C extends f {
|
|
|
372
361
|
if (!this.canDestroy) return this.isDestroyed;
|
|
373
362
|
const e = this._destroyers.toReversed();
|
|
374
363
|
e.push(this.destroyThis), this._destroyers.length = 0;
|
|
375
|
-
const
|
|
376
|
-
console.error("销毁函数在串行销毁时出错", this,
|
|
364
|
+
const t = h(e, this, null, (s, r) => {
|
|
365
|
+
console.error("销毁函数在串行销毁时出错", this, r, s);
|
|
377
366
|
});
|
|
378
|
-
return
|
|
367
|
+
return t instanceof Promise ? t.then(() => (o(this), !0)) : (o(this), !0);
|
|
379
368
|
}
|
|
380
369
|
}
|
|
381
370
|
export {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
371
|
+
c as D,
|
|
372
|
+
D as a,
|
|
373
|
+
f as b,
|
|
374
|
+
p as c,
|
|
375
|
+
o as d,
|
|
376
|
+
d as t
|
|
388
377
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const h=require("com-tools"),c=require("@gby/event-bus");class d{refCount=0;get isDestroyed(){return this._isDestroyed}_isDestroyed=!1;get canDestroy(){return!this.isDestroyed&&this.refCount<=0}_destroyers=[];disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const t=this._destroyers.indexOf(e);return this._destroyers.splice(t,1),e}disposeObj(e,t){const s=t?function(){return e.destroySync()}:function(){return e.destroy()};return this.disposeFun(s),e.__destroyable_destroyer=s,e}cancelDisposeObj(e){const t=e.__destroyable_destroyer;return t&&this.cancelDisposeFun(t),e}dispose(e,t){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,t)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const t=this._destroyers[e];try{t()}catch(s){console.error("销毁函数在同步销毁时出错",this,t,s)}}this._destroyers.length=0;try{this.destroyThis()}catch(t){console.error("destroyThis 在异步销毁时出错",this,t)}return o(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const e=this._destroyers.toReversed();e.push(this.destroyThis),this._destroyers.length=0;const t=h.serialCallAllFuns(e,this,null,(s,r)=>{console.error("销毁函数在串行销毁时出错",this,r,s)});return t instanceof Promise?t.then(()=>(o(this),!0)):(o(this),!0)}}function y(){throw"已销毁"}function l(i){for(var e in i)typeof i[e]=="function"&&(i[e]=y);return i._isDestroyed=!0,!0}function o(i){for(var e in i)!(e in d.prototype)&&typeof i[e]=="function"&&(i[e]=y);return i._isDestroyed=!0,!0}function a(i){class e extends i{refCount=0;get isDestroyed(){return this._isDestroyed}_isDestroyed=!1;get canDestroy(){return!this.isDestroyed&&this.refCount<=0}_destroyers=[];disposeFun(s){return this._destroyers.push(s),s}cancelDisposeFun(s){const r=this._destroyers.indexOf(s);return this._destroyers.splice(r,1),s}disposeObj(s,r){const n=r?function(){return s.destroySync()}:function(){return s.destroy()};return this.disposeFun(n),s.__destroyable_destroyer=n,s}cancelDisposeObj(s){const r=s.__destroyable_destroyer;return r&&this.cancelDisposeFun(r),s}dispose(s,r){return typeof s=="function"?this.disposeFun(s):this.disposeObj(s,r)}cancelDispose(s){return typeof s=="function"?this.cancelDisposeFun(s):this.cancelDisposeObj(s)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let s=this._destroyers.length;for(;--s>=0;){const r=this._destroyers[s];try{r()}catch(n){console.error("销毁函数在同步销毁时出错",this,r,n)}}this._destroyers.length=0;try{this.destroyThis()}catch(r){console.error("destroyThis 在异步销毁时出错",this,r)}return o(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const s=this._destroyers.toReversed();s.push(this.destroyThis),this._destroyers.length=0;const r=h.serialCallAllFuns(s,this,null,(n,u)=>{console.error("销毁函数在串行销毁时出错",this,u,n)});return r instanceof Promise?r.then(()=>(o(this),!0)):(o(this),!0)}}return e}class f extends c.EventBus{refCount=0;get isDestroyed(){return this._isDestroyed}_isDestroyed=!1;get canDestroy(){return!this.isDestroyed&&this.refCount<=0}_destroyers=[];disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const t=this._destroyers.indexOf(e);return this._destroyers.splice(t,1),e}disposeObj(e,t){const s=t?function(){return e.destroySync()}:function(){return e.destroy()};return this.disposeFun(s),e.__destroyable_destroyer=s,e}cancelDisposeObj(e){const t=e.__destroyable_destroyer;return t&&this.cancelDisposeFun(t),e}dispose(e,t){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,t)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const t=this._destroyers[e];try{t()}catch(s){console.error("销毁函数在同步销毁时出错",this,t,s)}}this._destroyers.length=0;try{this.destroyThis()}catch(t){console.error("destroyThis 在异步销毁时出错",this,t)}return o(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const e=this._destroyers.toReversed();e.push(this.destroyThis),this._destroyers.length=0;const t=h.serialCallAllFuns(e,this,null,(s,r)=>{console.error("销毁函数在串行销毁时出错",this,r,s)});return t instanceof Promise?t.then(()=>(o(this),!0)):(o(this),!0)}}exports.Destroyable=d;exports.DestroyableEventTarget=f;exports.createDestroyableSubClass=a;exports.destroyDestroyable=o;exports.destroyObject=l;exports.throwOnDestroyed=y;
|
|
@@ -17,12 +17,12 @@ export declare function createDestroyableSubClass<P extends new (...args: any) =
|
|
|
17
17
|
/**
|
|
18
18
|
* 是否已经销毁
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
get isDestroyed(): boolean;
|
|
21
21
|
_isDestroyed: boolean;
|
|
22
22
|
/**
|
|
23
23
|
* 是否可以销毁
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
get canDestroy(): boolean;
|
|
26
26
|
/**
|
|
27
27
|
* 销毁者
|
|
28
28
|
*/
|
package/dist/index-web.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./DestroyableEventTarget-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./DestroyableEventTarget-uZtYhcb1.cjs");exports.Destroyable=e.Destroyable;exports.DestroyableEventTarget=e.DestroyableEventTarget;exports.createDestroyableSubClass=e.createDestroyableSubClass;exports.destroyDestroyable=e.destroyDestroyable;exports.destroyObject=e.destroyObject;exports.throwOnDestroyed=e.throwOnDestroyed;
|
package/dist/index-web.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./DestroyableEventTarget-uZtYhcb1.cjs"),i=require("node:events"),n=require("com-tools");class y extends i.EventEmitter{refCount=0;get isDestroyed(){return this._isDestroyed}_isDestroyed=!1;get canDestroy(){return!this.isDestroyed&&this.refCount<=0}_destroyers=[];disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const t=this._destroyers.indexOf(e);return this._destroyers.splice(t,1),e}disposeObj(e,t){const r=t?function(){return e.destroySync()}:function(){return e.destroy()};return this.disposeFun(r),e.__destroyable_destroyer=r,e}cancelDisposeObj(e){const t=e.__destroyable_destroyer;return t&&this.cancelDisposeFun(t),e}dispose(e,t){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,t)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const t=this._destroyers[e];try{t()}catch(r){console.error("销毁函数在同步销毁时出错",this,t,r)}}this._destroyers.length=0;try{this.destroyThis()}catch(t){console.error("destroyThis 在异步销毁时出错",this,t)}return s.destroyDestroyable(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const e=this._destroyers.toReversed();e.push(this.destroyThis),this._destroyers.length=0;const t=n.serialCallAllFuns(e,this,null,(r,o)=>{console.error("销毁函数在串行销毁时出错",this,o,r)});return t instanceof Promise?t.then(()=>(s.destroyDestroyable(this),!0)):(s.destroyDestroyable(this),!0)}}exports.Destroyable=s.Destroyable;exports.DestroyableEventTarget=s.DestroyableEventTarget;exports.createDestroyableSubClass=s.createDestroyableSubClass;exports.destroyDestroyable=s.destroyDestroyable;exports.destroyObject=s.destroyObject;exports.throwOnDestroyed=s.throwOnDestroyed;exports.DestroyableEventEmitter=y;
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* 引用计数
|
|
13
|
-
* @remarks
|
|
14
|
-
* 引用计数为 0 时,对象才会被销毁
|
|
15
|
-
*/
|
|
16
|
-
i(this, "refCount", 0);
|
|
17
|
-
i(this, "_isDestroyed", !1);
|
|
18
|
-
/**
|
|
19
|
-
* 销毁者
|
|
20
|
-
*/
|
|
21
|
-
i(this, "_destroyers", []);
|
|
22
|
-
}
|
|
1
|
+
import { d as r } from "./DestroyableEventTarget-CIMBV0bD.js";
|
|
2
|
+
import { D as p, a as D, c as f, b as _, t as m } from "./DestroyableEventTarget-CIMBV0bD.js";
|
|
3
|
+
import { EventEmitter as i } from "node:events";
|
|
4
|
+
import { serialCallAllFuns as n } from "com-tools";
|
|
5
|
+
class u extends i {
|
|
6
|
+
/**
|
|
7
|
+
* 引用计数
|
|
8
|
+
* @remarks
|
|
9
|
+
* 引用计数为 0 时,对象才会被销毁
|
|
10
|
+
*/
|
|
11
|
+
refCount = 0;
|
|
23
12
|
/**
|
|
24
13
|
* 是否已经销毁
|
|
25
14
|
*/
|
|
26
15
|
get isDestroyed() {
|
|
27
16
|
return this._isDestroyed;
|
|
28
17
|
}
|
|
18
|
+
_isDestroyed = !1;
|
|
29
19
|
/**
|
|
30
20
|
* 是否可以销毁
|
|
31
21
|
*/
|
|
32
22
|
get canDestroy() {
|
|
33
23
|
return !this.isDestroyed && this.refCount <= 0;
|
|
34
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* 销毁者
|
|
27
|
+
*/
|
|
28
|
+
_destroyers = [];
|
|
35
29
|
/**
|
|
36
30
|
* 添加销毁者
|
|
37
31
|
* @param fun
|
|
@@ -56,12 +50,12 @@ class f extends c {
|
|
|
56
50
|
* @returns
|
|
57
51
|
*/
|
|
58
52
|
disposeObj(e, s) {
|
|
59
|
-
const
|
|
53
|
+
const t = s ? function() {
|
|
60
54
|
return e.destroySync();
|
|
61
55
|
} : function() {
|
|
62
56
|
return e.destroy();
|
|
63
57
|
};
|
|
64
|
-
return this.disposeFun(
|
|
58
|
+
return this.disposeFun(t), e.__destroyable_destroyer = t, e;
|
|
65
59
|
}
|
|
66
60
|
/**
|
|
67
61
|
* 取消销毁者函数
|
|
@@ -97,8 +91,8 @@ class f extends c {
|
|
|
97
91
|
const s = this._destroyers[e];
|
|
98
92
|
try {
|
|
99
93
|
s();
|
|
100
|
-
} catch (
|
|
101
|
-
console.error("销毁函数在同步销毁时出错", this, s,
|
|
94
|
+
} catch (t) {
|
|
95
|
+
console.error("销毁函数在同步销毁时出错", this, s, t);
|
|
102
96
|
}
|
|
103
97
|
}
|
|
104
98
|
this._destroyers.length = 0;
|
|
@@ -107,7 +101,7 @@ class f extends c {
|
|
|
107
101
|
} catch (s) {
|
|
108
102
|
console.error("destroyThis 在异步销毁时出错", this, s);
|
|
109
103
|
}
|
|
110
|
-
return
|
|
104
|
+
return r(this), !0;
|
|
111
105
|
}
|
|
112
106
|
/**
|
|
113
107
|
* 串行销毁
|
|
@@ -119,18 +113,18 @@ class f extends c {
|
|
|
119
113
|
if (!this.canDestroy) return this.isDestroyed;
|
|
120
114
|
const e = this._destroyers.toReversed();
|
|
121
115
|
e.push(this.destroyThis), this._destroyers.length = 0;
|
|
122
|
-
const s =
|
|
123
|
-
console.error("销毁函数在串行销毁时出错", this,
|
|
116
|
+
const s = n(e, this, null, (t, o) => {
|
|
117
|
+
console.error("销毁函数在串行销毁时出错", this, o, t);
|
|
124
118
|
});
|
|
125
|
-
return s instanceof Promise ? s.then(() => (
|
|
119
|
+
return s instanceof Promise ? s.then(() => (r(this), !0)) : (r(this), !0);
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
122
|
export {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
123
|
+
p as Destroyable,
|
|
124
|
+
u as DestroyableEventEmitter,
|
|
125
|
+
D as DestroyableEventTarget,
|
|
126
|
+
f as createDestroyableSubClass,
|
|
127
|
+
r as destroyDestroyable,
|
|
128
|
+
_ as destroyObject,
|
|
129
|
+
m as throwOnDestroyed
|
|
136
130
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gby/destroyable",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "@gby/destroyable 提供了用于构建可销毁对象的类的基类,用于使得地管理可销毁对象的生命周期",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@microsoft/api-documenter": "latest",
|
|
47
47
|
"@microsoft/api-extractor": "latest",
|
|
48
|
-
"@types/node": "^
|
|
48
|
+
"@types/node": "^25.3.2",
|
|
49
49
|
"build-tls": "latest",
|
|
50
50
|
"dts-bundle-generator": "latest",
|
|
51
51
|
"package-tls": "latest",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"vite-node": "latest"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@gby/event-bus": "^1.
|
|
59
|
-
"com-tools": "^2.21.
|
|
58
|
+
"@gby/event-bus": "^1.3.0",
|
|
59
|
+
"com-tools": "^2.21.2"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"serve": "vite",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var a=Object.defineProperty;var f=(i,s,e)=>s in i?a(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var n=(i,s,e)=>f(i,typeof s!="symbol"?s+"":s,e);const d=require("com-tools"),D=require("@gby/event-bus");class c{constructor(){n(this,"refCount",0);n(this,"_isDestroyed",!1);n(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}get canDestroy(){return!this.isDestroyed&&this.refCount<=0}disposeFun(s){return this._destroyers.push(s),s}cancelDisposeFun(s){const e=this._destroyers.indexOf(s);return this._destroyers.splice(e,1),s}disposeObj(s,e){const r=e?function(){return s.destroySync()}:function(){return s.destroy()};return this.disposeFun(r),s.__destroyable_destroyer=r,s}cancelDisposeObj(s){const e=s.__destroyable_destroyer;return e&&this.cancelDisposeFun(e),s}dispose(s,e){return typeof s=="function"?this.disposeFun(s):this.disposeObj(s,e)}cancelDispose(s){return typeof s=="function"?this.cancelDisposeFun(s):this.cancelDisposeObj(s)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let s=this._destroyers.length;for(;--s>=0;){const e=this._destroyers[s];try{e()}catch(r){console.error("销毁函数在同步销毁时出错",this,e,r)}}this._destroyers.length=0;try{this.destroyThis()}catch(e){console.error("destroyThis 在异步销毁时出错",this,e)}return h(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const s=this._destroyers.toReversed();s.push(this.destroyThis),this._destroyers.length=0;const e=d.serialCallAllFuns(s,this,null,(r,t)=>{console.error("销毁函数在串行销毁时出错",this,t,r)});return e instanceof Promise?e.then(()=>(h(this),!0)):(h(this),!0)}}function u(){throw"已销毁"}function p(i){for(var s in i)typeof i[s]=="function"&&(i[s]=u);return i._isDestroyed=!0,!0}function h(i){for(var s in i)!(s in c.prototype)&&typeof i[s]=="function"&&(i[s]=u);return i._isDestroyed=!0,!0}function _(i){class s extends i{constructor(){super(...arguments);n(this,"refCount",0);n(this,"_isDestroyed",!1);n(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}get canDestroy(){return!this.isDestroyed&&this.refCount<=0}disposeFun(t){return this._destroyers.push(t),t}cancelDisposeFun(t){const o=this._destroyers.indexOf(t);return this._destroyers.splice(o,1),t}disposeObj(t,o){const y=o?function(){return t.destroySync()}:function(){return t.destroy()};return this.disposeFun(y),t.__destroyable_destroyer=y,t}cancelDisposeObj(t){const o=t.__destroyable_destroyer;return o&&this.cancelDisposeFun(o),t}dispose(t,o){return typeof t=="function"?this.disposeFun(t):this.disposeObj(t,o)}cancelDispose(t){return typeof t=="function"?this.cancelDisposeFun(t):this.cancelDisposeObj(t)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let t=this._destroyers.length;for(;--t>=0;){const o=this._destroyers[t];try{o()}catch(y){console.error("销毁函数在同步销毁时出错",this,o,y)}}this._destroyers.length=0;try{this.destroyThis()}catch(o){console.error("destroyThis 在异步销毁时出错",this,o)}return h(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const t=this._destroyers.toReversed();t.push(this.destroyThis),this._destroyers.length=0;const o=d.serialCallAllFuns(t,this,null,(y,l)=>{console.error("销毁函数在串行销毁时出错",this,l,y)});return o instanceof Promise?o.then(()=>(h(this),!0)):(h(this),!0)}}return s}class g extends D.EventBus{constructor(){super(...arguments);n(this,"refCount",0);n(this,"_isDestroyed",!1);n(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}get canDestroy(){return!this.isDestroyed&&this.refCount<=0}disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const r=this._destroyers.indexOf(e);return this._destroyers.splice(r,1),e}disposeObj(e,r){const t=r?function(){return e.destroySync()}:function(){return e.destroy()};return this.disposeFun(t),e.__destroyable_destroyer=t,e}cancelDisposeObj(e){const r=e.__destroyable_destroyer;return r&&this.cancelDisposeFun(r),e}dispose(e,r){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,r)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const r=this._destroyers[e];try{r()}catch(t){console.error("销毁函数在同步销毁时出错",this,r,t)}}this._destroyers.length=0;try{this.destroyThis()}catch(r){console.error("destroyThis 在异步销毁时出错",this,r)}return h(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const e=this._destroyers.toReversed();e.push(this.destroyThis),this._destroyers.length=0;const r=d.serialCallAllFuns(e,this,null,(t,o)=>{console.error("销毁函数在串行销毁时出错",this,o,t)});return r instanceof Promise?r.then(()=>(h(this),!0)):(h(this),!0)}}exports.Destroyable=c;exports.DestroyableEventTarget=g;exports.createDestroyableSubClass=_;exports.destroyDestroyable=h;exports.destroyObject=p;exports.throwOnDestroyed=u;
|