@gby/destroyable 3.4.1 → 3.6.0

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.
@@ -62,17 +62,20 @@ export declare class Destroyable implements IDestroyable {
62
62
  * @remarks
63
63
  * 子类根据需要进行重载
64
64
  */
65
- destroyThis(): Promise<void> | void;
65
+ destroyThis(): any;
66
66
  /**
67
- * 销毁
67
+ * 同步销毁
68
+ * @remarks
69
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
68
70
  */
69
71
  destroySync(): boolean;
70
72
  /**
71
- * 异步销毁
73
+ * 串行销毁
72
74
  * @remarks
73
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
75
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
76
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
74
77
  */
75
- destroy(): Promise<boolean>;
78
+ destroy(): boolean | Promise<boolean>;
76
79
  }
77
80
  /**
78
81
  * 调用已销对象的时抛出错误
@@ -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,SAAK;IAEb;;OAEG;IACH,IAAI,WAAW,YAEd;IACD,YAAY,UAAS;IAErB;;OAEG;IACH,IAAI,UAAU,YAEb;IAED;;OAEG;IACH,WAAW,EAAE,YAAY,EAAE,CAAM;IAEjC;;;;OAIG;IACH,UAAU,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAK7C;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG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AgB,gBAAgB,SAE/B;AAKD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,WASxC;AAKD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,WAYtD"}
@@ -65,16 +65,19 @@ export declare class DestroyableEventEmitter<EM extends EventMap<EM> = DefaultEv
65
65
  * @remarks
66
66
  * 子类根据需要进行重载
67
67
  */
68
- destroyThis(): Promise<void> | void;
68
+ destroyThis(): any;
69
69
  /**
70
- * 销毁
70
+ * 同步销毁
71
+ * @remarks
72
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
71
73
  */
72
74
  destroySync(): boolean;
73
75
  /**
74
- * 异步销毁
76
+ * 串行销毁
75
77
  * @remarks
76
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
78
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
79
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
77
80
  */
78
- destroy(): Promise<boolean>;
81
+ destroy(): boolean | Promise<boolean>;
79
82
  }
80
83
  //# sourceMappingURL=DestroyableEventEmitter.d.ts.map
@@ -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;AAG3C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC;AACnE,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC,CAAC;AAEtC;;GAEG;AACH,qBAAa,uBAAuB,CAAC,EAAE,SAAS,QAAQ,CAAC,EAAE,CAAC,GAAG,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SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,CAAC;IAClE,OAAO,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,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"}
@@ -0,0 +1 @@
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;
@@ -1,20 +1,21 @@
1
- var d = Object.defineProperty;
2
- var u = (o, s, e) => s in o ? d(o, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[s] = e;
3
- var h = (o, s, e) => u(o, typeof s != "symbol" ? s + "" : s, e);
4
- import { EventBus as a } from "@gby/event-bus";
5
- class l {
1
+ var l = Object.defineProperty;
2
+ var a = (i, s, e) => s in i ? l(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
3
+ var n = (i, s, e) => a(i, typeof s != "symbol" ? s + "" : s, e);
4
+ import { serialCallAllFuns as y } from "com-tools";
5
+ import { EventBus as f } from "@gby/event-bus";
6
+ class p {
6
7
  constructor() {
7
8
  /**
8
9
  * 引用计数
9
10
  * @remarks
10
11
  * 引用计数为 0 时,对象才会被销毁
11
12
  */
12
- h(this, "refCount", 0);
13
- h(this, "_isDestroyed", !1);
13
+ n(this, "refCount", 0);
14
+ n(this, "_isDestroyed", !1);
14
15
  /**
15
16
  * 销毁者
16
17
  */
17
- h(this, "_destroyers", []);
18
+ n(this, "_destroyers", []);
18
19
  }
19
20
  /**
20
21
  * 是否已经销毁
@@ -82,7 +83,9 @@ class l {
82
83
  destroyThis() {
83
84
  }
84
85
  /**
85
- * 销毁
86
+ * 同步销毁
87
+ * @remarks
88
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
86
89
  */
87
90
  destroySync() {
88
91
  if (!this.canDestroy) return this.isDestroyed;
@@ -101,50 +104,39 @@ class l {
101
104
  } catch (e) {
102
105
  console.error("destroyThis 在异步销毁时出错", this, e);
103
106
  }
104
- return y(this), !0;
107
+ return h(this), !0;
105
108
  }
106
109
  /**
107
- * 异步销毁
110
+ * 串行销毁
108
111
  * @remarks
109
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
112
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
113
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
110
114
  */
111
- async destroy() {
115
+ destroy() {
112
116
  if (!this.canDestroy) return this.isDestroyed;
113
- let s = this._destroyers.length;
114
- for (; --s >= 0; ) {
115
- const e = this._destroyers[s];
116
- try {
117
- const r = e();
118
- r && r instanceof Promise && await r;
119
- } catch (r) {
120
- console.error("销毁函数在异步销毁时出错", this, e, r);
121
- }
122
- }
123
- this._destroyers.length = 0;
124
- try {
125
- const e = this.destroyThis();
126
- e && e instanceof Promise && await e;
127
- } catch (e) {
128
- console.error("destroyThis 在异步销毁时出错", this, e);
129
- }
130
- return y(this), !0;
117
+ const s = this._destroyers.toReversed();
118
+ s.push(this.destroyThis), this._destroyers.length = 0;
119
+ const e = y(s, this, null, (r, t) => {
120
+ console.error("销毁函数在串行销毁时出错", this, t, r);
121
+ });
122
+ return e instanceof Promise ? e.then(() => (h(this), !0)) : (h(this), !0);
131
123
  }
132
124
  }
133
- function c() {
125
+ function u() {
134
126
  throw "已销毁";
135
127
  }
136
- function p(o) {
137
- for (var s in o)
138
- typeof o[s] == "function" && (o[s] = c);
139
- return o._isDestroyed = !0, !0;
128
+ function T(i) {
129
+ for (var s in i)
130
+ typeof i[s] == "function" && (i[s] = u);
131
+ return i._isDestroyed = !0, !0;
140
132
  }
141
- function y(o) {
142
- for (var s in o)
143
- !(s in l.prototype) && typeof o[s] == "function" && (o[s] = c);
144
- return o._isDestroyed = !0, !0;
133
+ function h(i) {
134
+ for (var s in i)
135
+ !(s in p.prototype) && typeof i[s] == "function" && (i[s] = u);
136
+ return i._isDestroyed = !0, !0;
145
137
  }
146
- function D(o) {
147
- class s extends o {
138
+ function x(i) {
139
+ class s extends i {
148
140
  constructor() {
149
141
  super(...arguments);
150
142
  /**
@@ -152,12 +144,12 @@ function D(o) {
152
144
  * @remarks
153
145
  * 引用计数为 0 时,对象才会被销毁
154
146
  */
155
- h(this, "refCount", 0);
156
- h(this, "_isDestroyed", !1);
147
+ n(this, "refCount", 0);
148
+ n(this, "_isDestroyed", !1);
157
149
  /**
158
150
  * 销毁者
159
151
  */
160
- h(this, "_destroyers", []);
152
+ n(this, "_destroyers", []);
161
153
  }
162
154
  /**
163
155
  * 是否已经销毁
@@ -185,8 +177,8 @@ function D(o) {
185
177
  * @returns
186
178
  */
187
179
  cancelDisposeFun(t) {
188
- const i = this._destroyers.indexOf(t);
189
- return this._destroyers.splice(i, 1), t;
180
+ const o = this._destroyers.indexOf(t);
181
+ return this._destroyers.splice(o, 1), t;
190
182
  }
191
183
  /**
192
184
  * 添加销毁对象
@@ -194,13 +186,13 @@ function D(o) {
194
186
  * @param sync - 表示是否使用 `obj.destroySync()` 方法进行销毁;默认使用 `obj.destroy()` 方法进行销毁
195
187
  * @returns
196
188
  */
197
- disposeObj(t, i) {
198
- const n = i ? function() {
189
+ disposeObj(t, o) {
190
+ const d = o ? function() {
199
191
  return t.destroySync();
200
192
  } : function() {
201
193
  return t.destroy();
202
194
  };
203
- return this.disposeFun(n), t.__destroyable_destroyer = n, t;
195
+ return this.disposeFun(d), t.__destroyable_destroyer = d, t;
204
196
  }
205
197
  /**
206
198
  * 取消销毁者函数
@@ -208,11 +200,11 @@ function D(o) {
208
200
  * @returns
209
201
  */
210
202
  cancelDisposeObj(t) {
211
- const i = t.__destroyable_destroyer;
212
- return i && this.cancelDisposeFun(i), t;
203
+ const o = t.__destroyable_destroyer;
204
+ return o && this.cancelDisposeFun(o), t;
213
205
  }
214
- dispose(t, i) {
215
- return typeof t == "function" ? this.disposeFun(t) : this.disposeObj(t, i);
206
+ dispose(t, o) {
207
+ return typeof t == "function" ? this.disposeFun(t) : this.disposeObj(t, o);
216
208
  }
217
209
  cancelDispose(t) {
218
210
  return typeof t == "function" ? this.cancelDisposeFun(t) : this.cancelDisposeObj(t);
@@ -225,59 +217,48 @@ function D(o) {
225
217
  destroyThis() {
226
218
  }
227
219
  /**
228
- * 异步销毁
220
+ * 同步销毁
229
221
  * @remarks
230
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
222
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
231
223
  */
232
- async destroy() {
224
+ destroySync() {
233
225
  if (!this.canDestroy) return this.isDestroyed;
234
226
  let t = this._destroyers.length;
235
227
  for (; --t >= 0; ) {
236
- const i = this._destroyers[t];
228
+ const o = this._destroyers[t];
237
229
  try {
238
- const n = i();
239
- n && n instanceof Promise && await n;
240
- } catch (n) {
241
- console.error("销毁函数在异步销毁时出错", this, i, n);
230
+ o();
231
+ } catch (d) {
232
+ console.error("销毁函数在同步销毁时出错", this, o, d);
242
233
  }
243
234
  }
244
235
  this._destroyers.length = 0;
245
236
  try {
246
- const i = this.destroyThis();
247
- i && i instanceof Promise && await i;
248
- } catch (i) {
249
- console.error("destroyThis 在异步销毁时出错", this, i);
237
+ this.destroyThis();
238
+ } catch (o) {
239
+ console.error("destroyThis 在异步销毁时出错", this, o);
250
240
  }
251
- return y(this), !0;
241
+ return h(this), !0;
252
242
  }
253
243
  /**
254
- * 同步销毁
244
+ * 串行销毁
255
245
  * @remarks
256
- * 会依次执行销毁函数,但并不会等待每个异步销毁函数解决
246
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
247
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
257
248
  */
258
- destroySync() {
249
+ destroy() {
259
250
  if (!this.canDestroy) return this.isDestroyed;
260
- let t = this._destroyers.length;
261
- for (; --t >= 0; ) {
262
- const i = this._destroyers[t];
263
- try {
264
- i();
265
- } catch (n) {
266
- console.error("销毁函数在同步销毁时出错", this, i, n);
267
- }
268
- }
269
- this._destroyers.length = 0;
270
- try {
271
- this.destroyThis();
272
- } catch (i) {
273
- console.error("destroyThis 在异步销毁时出错", this, i);
274
- }
275
- return y(this), !0;
251
+ const t = this._destroyers.toReversed();
252
+ t.push(this.destroyThis), this._destroyers.length = 0;
253
+ const o = y(t, this, null, (d, c) => {
254
+ console.error("销毁函数在串行销毁时出错", this, c, d);
255
+ });
256
+ return o instanceof Promise ? o.then(() => (h(this), !0)) : (h(this), !0);
276
257
  }
277
258
  }
278
259
  return s;
279
260
  }
280
- class g extends a {
261
+ class C extends f {
281
262
  constructor() {
282
263
  super(...arguments);
283
264
  /**
@@ -285,12 +266,12 @@ class g extends a {
285
266
  * @remarks
286
267
  * 引用计数为 0 时,对象才会被销毁
287
268
  */
288
- h(this, "refCount", 0);
289
- h(this, "_isDestroyed", !1);
269
+ n(this, "refCount", 0);
270
+ n(this, "_isDestroyed", !1);
290
271
  /**
291
272
  * 销毁者
292
273
  */
293
- h(this, "_destroyers", []);
274
+ n(this, "_destroyers", []);
294
275
  }
295
276
  /**
296
277
  * 是否已经销毁
@@ -358,7 +339,9 @@ class g extends a {
358
339
  destroyThis() {
359
340
  }
360
341
  /**
361
- * 销毁
342
+ * 同步销毁
343
+ * @remarks
344
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
362
345
  */
363
346
  destroySync() {
364
347
  if (!this.canDestroy) return this.isDestroyed;
@@ -377,40 +360,29 @@ class g extends a {
377
360
  } catch (r) {
378
361
  console.error("destroyThis 在异步销毁时出错", this, r);
379
362
  }
380
- return y(this), !0;
363
+ return h(this), !0;
381
364
  }
382
365
  /**
383
- * 异步销毁
366
+ * 串行销毁
384
367
  * @remarks
385
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
368
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
369
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
386
370
  */
387
- async destroy() {
371
+ destroy() {
388
372
  if (!this.canDestroy) return this.isDestroyed;
389
- let e = this._destroyers.length;
390
- for (; --e >= 0; ) {
391
- const r = this._destroyers[e];
392
- try {
393
- const t = r();
394
- t && t instanceof Promise && await t;
395
- } catch (t) {
396
- console.error("销毁函数在异步销毁时出错", this, r, t);
397
- }
398
- }
399
- this._destroyers.length = 0;
400
- try {
401
- const r = this.destroyThis();
402
- r && r instanceof Promise && await r;
403
- } catch (r) {
404
- console.error("destroyThis 在异步销毁时出错", this, r);
405
- }
406
- return y(this), !0;
373
+ const e = this._destroyers.toReversed();
374
+ e.push(this.destroyThis), this._destroyers.length = 0;
375
+ const r = y(e, this, null, (t, o) => {
376
+ console.error("销毁函数在串行销毁时出错", this, o, t);
377
+ });
378
+ return r instanceof Promise ? r.then(() => (h(this), !0)) : (h(this), !0);
407
379
  }
408
380
  }
409
381
  export {
410
- l as D,
411
- y as a,
412
- g as b,
413
- D as c,
414
- p as d,
415
- c as t
382
+ p as D,
383
+ h as a,
384
+ C as b,
385
+ x as c,
386
+ T as d,
387
+ u as t
416
388
  };
@@ -63,16 +63,19 @@ export declare class DestroyableEventTarget<EM extends Record<string, any> = Rec
63
63
  * @remarks
64
64
  * 子类根据需要进行重载
65
65
  */
66
- destroyThis(): Promise<void> | void;
66
+ destroyThis(): any;
67
67
  /**
68
- * 销毁
68
+ * 同步销毁
69
+ * @remarks
70
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
69
71
  */
70
72
  destroySync(): boolean;
71
73
  /**
72
- * 异步销毁
74
+ * 串行销毁
73
75
  * @remarks
74
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
76
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
77
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
75
78
  */
76
- destroy(): Promise<boolean>;
79
+ destroy(): boolean | Promise<boolean>;
77
80
  }
78
81
  //# sourceMappingURL=DestroyableEventTarget.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DestroyableEventTarget.d.ts","sourceRoot":"","sources":["../src/DestroyableEventTarget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEzD,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,qBAAa,sBAAsB,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,SAAQ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AE,CAAC,EAAE,YAAY,CAAC,EAAE,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;IAapE;;;;OAIG;IACH,WAAW,IAAI,GAAG;IAKlB;;;;OAIG;IACH,WAAW;IA6BX;;;;;OAKG;IACH,OAAO;CAuBV"}
@@ -67,19 +67,20 @@ export declare function createDestroyableSubClass<P extends new (...args: any) =
67
67
  * @remarks
68
68
  * 子类根据需要进行重载
69
69
  */
70
- destroyThis(): Promise<void> | void;
70
+ destroyThis(): any;
71
71
  /**
72
- * 异步销毁
72
+ * 同步销毁
73
73
  * @remarks
74
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
74
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
75
75
  */
76
- destroy(): Promise<boolean>;
76
+ destroySync(): boolean;
77
77
  /**
78
- * 同步销毁
78
+ * 串行销毁
79
79
  * @remarks
80
- * 会依次执行销毁函数,但并不会等待每个异步销毁函数解决
80
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
81
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
81
82
  */
82
- destroySync(): boolean;
83
+ destroy(): boolean | Promise<boolean>;
83
84
  constructor: Function;
84
85
  toString(): string;
85
86
  toLocaleString(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"createDestroyableSubClass.d.ts","sourceRoot":"","sources":["../src/createDestroyableSubClass.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAC,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGxD;;;;;;GAMG;AACH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AAI,UAAU,CAAC,OAAO,yBAAyB,CAAC,WAAW,CAAC,CAAC,CAAC;AAE9I;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,WAAW,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,IAAI,YAAY,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./DestroyableEventTarget-DSGfqvV0.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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./DestroyableEventTarget-D6QEuQ_5.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
@@ -1,4 +1,4 @@
1
- import { D as a, b as t, c as r, a as o, d as b, t as y } from "./DestroyableEventTarget-DFVzomDG.js";
1
+ import { D as a, b as t, c as r, a as o, d as b, t as y } from "./DestroyableEventTarget-DdEIvJNx.js";
2
2
  export {
3
3
  a as Destroyable,
4
4
  t as DestroyableEventTarget,
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var y=Object.defineProperty;var d=(i,r,e)=>r in i?y(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e;var n=(i,r,e)=>d(i,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./DestroyableEventTarget-DSGfqvV0.cjs"),c=require("node:events");class h extends c.EventEmitter{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 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.destroyDestroyable(this),!0}async destroy(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const t=this._destroyers[e];try{const s=t();s&&s instanceof Promise&&await s}catch(s){console.error("销毁函数在异步销毁时出错",this,t,s)}}this._destroyers.length=0;try{const t=this.destroyThis();t&&t instanceof Promise&&await t}catch(t){console.error("destroyThis 在异步销毁时出错",this,t)}return o.destroyDestroyable(this),!0}}exports.Destroyable=o.Destroyable;exports.DestroyableEventTarget=o.DestroyableEventTarget;exports.createDestroyableSubClass=o.createDestroyableSubClass;exports.destroyDestroyable=o.destroyDestroyable;exports.destroyObject=o.destroyObject;exports.throwOnDestroyed=o.throwOnDestroyed;exports.DestroyableEventEmitter=h;
1
+ "use strict";var d=Object.defineProperty;var c=(o,r,e)=>r in o?d(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e;var n=(o,r,e)=>c(o,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./DestroyableEventTarget-D6QEuQ_5.cjs"),l=require("node:events"),h=require("com-tools");class u extends l.EventEmitter{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 t=this._destroyers.indexOf(e);return this._destroyers.splice(t,1),e}disposeObj(e,t){const i=t?function(){return e.destroySync()}:function(){return e.destroy()};return this.disposeFun(i),e.__destroyable_destroyer=i,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(i){console.error("销毁函数在同步销毁时出错",this,t,i)}}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=h.serialCallAllFuns(e,this,null,(i,y)=>{console.error("销毁函数在串行销毁时出错",this,y,i)});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=u;
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
- var y = Object.defineProperty;
2
- var c = (o, r, e) => r in o ? y(o, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[r] = e;
3
- var i = (o, r, e) => c(o, typeof r != "symbol" ? r + "" : r, e);
4
- import { a as n } from "./DestroyableEventTarget-DFVzomDG.js";
5
- import { D as p, b as _, c as m, d as g, t as x } from "./DestroyableEventTarget-DFVzomDG.js";
6
- import { EventEmitter as d } from "node:events";
7
- class u extends d {
1
+ var d = Object.defineProperty;
2
+ var h = (r, t, e) => t in r ? d(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var i = (r, t, e) => h(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import { a as n } from "./DestroyableEventTarget-DdEIvJNx.js";
5
+ import { D as b, b as g, c as x, d as E, t as T } from "./DestroyableEventTarget-DdEIvJNx.js";
6
+ import { EventEmitter as c } from "node:events";
7
+ import { serialCallAllFuns as u } from "com-tools";
8
+ class f extends c {
8
9
  constructor() {
9
10
  super(...arguments);
10
11
  /**
@@ -55,12 +56,12 @@ class u extends d {
55
56
  * @returns
56
57
  */
57
58
  disposeObj(e, s) {
58
- const t = s ? function() {
59
+ const o = s ? function() {
59
60
  return e.destroySync();
60
61
  } : function() {
61
62
  return e.destroy();
62
63
  };
63
- return this.disposeFun(t), e.__destroyable_destroyer = t, e;
64
+ return this.disposeFun(o), e.__destroyable_destroyer = o, e;
64
65
  }
65
66
  /**
66
67
  * 取消销毁者函数
@@ -85,7 +86,9 @@ class u extends d {
85
86
  destroyThis() {
86
87
  }
87
88
  /**
88
- * 销毁
89
+ * 同步销毁
90
+ * @remarks
91
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
89
92
  */
90
93
  destroySync() {
91
94
  if (!this.canDestroy) return this.isDestroyed;
@@ -94,8 +97,8 @@ class u extends d {
94
97
  const s = this._destroyers[e];
95
98
  try {
96
99
  s();
97
- } catch (t) {
98
- console.error("销毁函数在同步销毁时出错", this, s, t);
100
+ } catch (o) {
101
+ console.error("销毁函数在同步销毁时出错", this, s, o);
99
102
  }
100
103
  }
101
104
  this._destroyers.length = 0;
@@ -107,38 +110,27 @@ class u extends d {
107
110
  return n(this), !0;
108
111
  }
109
112
  /**
110
- * 异步销毁
113
+ * 串行销毁
111
114
  * @remarks
112
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
115
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
116
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
113
117
  */
114
- async destroy() {
118
+ destroy() {
115
119
  if (!this.canDestroy) return this.isDestroyed;
116
- let e = this._destroyers.length;
117
- for (; --e >= 0; ) {
118
- const s = this._destroyers[e];
119
- try {
120
- const t = s();
121
- t && t instanceof Promise && await t;
122
- } catch (t) {
123
- console.error("销毁函数在异步销毁时出错", this, s, t);
124
- }
125
- }
126
- this._destroyers.length = 0;
127
- try {
128
- const s = this.destroyThis();
129
- s && s instanceof Promise && await s;
130
- } catch (s) {
131
- console.error("destroyThis 在异步销毁时出错", this, s);
132
- }
133
- return n(this), !0;
120
+ const e = this._destroyers.toReversed();
121
+ e.push(this.destroyThis), this._destroyers.length = 0;
122
+ const s = u(e, this, null, (o, y) => {
123
+ console.error("销毁函数在串行销毁时出错", this, y, o);
124
+ });
125
+ return s instanceof Promise ? s.then(() => (n(this), !0)) : (n(this), !0);
134
126
  }
135
127
  }
136
128
  export {
137
- p as Destroyable,
138
- u as DestroyableEventEmitter,
139
- _ as DestroyableEventTarget,
140
- m as createDestroyableSubClass,
129
+ b as Destroyable,
130
+ f as DestroyableEventEmitter,
131
+ g as DestroyableEventTarget,
132
+ x as createDestroyableSubClass,
141
133
  n as destroyDestroyable,
142
- g as destroyObject,
143
- x as throwOnDestroyed
134
+ E as destroyObject,
135
+ T as throwOnDestroyed
144
136
  };
package/dist/type.d.ts CHANGED
@@ -48,13 +48,16 @@ export interface IDestroyable {
48
48
  cancelDispose<T extends IDestroyable>(obj: T): T;
49
49
  cancelDispose<T extends IDestroyable | FunDestroyer>(objOrFun: T): T;
50
50
  /**
51
- * 异步销毁
51
+ * 串行销毁
52
52
  * @remarks
53
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
53
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
54
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
54
55
  */
55
- destroy(): Promise<boolean>;
56
+ destroy(): boolean | Promise<boolean>;
56
57
  /**
57
- * 销毁
58
+ * 同步销毁
59
+ * @remarks
60
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
58
61
  */
59
62
  destroySync(): boolean;
60
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC;AAQtC;;GAEG;AACH,MAAM,WAAW,YAAY;IAEzB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,UAAU,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAE9C;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAEpD;;;;;OAKG;IACH,UAAU,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,EAAC,IAAI,CAAC,EAAC,OAAO,GAAG,CAAC,CAAC;IAE5D;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAEpD;;;OAGG;IACH,OAAO,CAAC,CAAC,SAAS,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO,CAAC,CAAC,SAAS,YAAY,EAAE,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AAG,GAAE,YAAY,CAAC;IAChC,SAAS,EAAC,YAAY,CAAC;CAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gby/destroyable",
3
- "version": "3.4.1",
3
+ "version": "3.6.0",
4
4
  "description": "@gby/destroyable 提供了用于构建可销毁对象的类的基类,用于使得地管理可销毁对象的生命周期",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -55,7 +55,8 @@
55
55
  "vite-node": "latest"
56
56
  },
57
57
  "dependencies": {
58
- "@gby/event-bus": "^1.2.3"
58
+ "@gby/event-bus": "^1.2.3",
59
+ "com-tools": "^2.21.1"
59
60
  },
60
61
  "scripts": {
61
62
  "serve": "vite",
@@ -1 +0,0 @@
1
- "use strict";var u=Object.defineProperty;var a=(o,s,e)=>s in o?u(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var y=(o,s,e)=>a(o,typeof s!="symbol"?s+"":s,e);const l=require("@gby/event-bus");class d{constructor(){y(this,"refCount",0);y(this,"_isDestroyed",!1);y(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 c(this),!0}async destroy(){if(!this.canDestroy)return this.isDestroyed;let s=this._destroyers.length;for(;--s>=0;){const e=this._destroyers[s];try{const r=e();r&&r instanceof Promise&&await r}catch(r){console.error("销毁函数在异步销毁时出错",this,e,r)}}this._destroyers.length=0;try{const e=this.destroyThis();e&&e instanceof Promise&&await e}catch(e){console.error("destroyThis 在异步销毁时出错",this,e)}return c(this),!0}}function h(){throw"已销毁"}function f(o){for(var s in o)typeof o[s]=="function"&&(o[s]=h);return o._isDestroyed=!0,!0}function c(o){for(var s in o)!(s in d.prototype)&&typeof o[s]=="function"&&(o[s]=h);return o._isDestroyed=!0,!0}function D(o){class s extends o{constructor(){super(...arguments);y(this,"refCount",0);y(this,"_isDestroyed",!1);y(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 i=this._destroyers.indexOf(t);return this._destroyers.splice(i,1),t}disposeObj(t,i){const n=i?function(){return t.destroySync()}:function(){return t.destroy()};return this.disposeFun(n),t.__destroyable_destroyer=n,t}cancelDisposeObj(t){const i=t.__destroyable_destroyer;return i&&this.cancelDisposeFun(i),t}dispose(t,i){return typeof t=="function"?this.disposeFun(t):this.disposeObj(t,i)}cancelDispose(t){return typeof t=="function"?this.cancelDisposeFun(t):this.cancelDisposeObj(t)}destroyThis(){}async destroy(){if(!this.canDestroy)return this.isDestroyed;let t=this._destroyers.length;for(;--t>=0;){const i=this._destroyers[t];try{const n=i();n&&n instanceof Promise&&await n}catch(n){console.error("销毁函数在异步销毁时出错",this,i,n)}}this._destroyers.length=0;try{const i=this.destroyThis();i&&i instanceof Promise&&await i}catch(i){console.error("destroyThis 在异步销毁时出错",this,i)}return c(this),!0}destroySync(){if(!this.canDestroy)return this.isDestroyed;let t=this._destroyers.length;for(;--t>=0;){const i=this._destroyers[t];try{i()}catch(n){console.error("销毁函数在同步销毁时出错",this,i,n)}}this._destroyers.length=0;try{this.destroyThis()}catch(i){console.error("destroyThis 在异步销毁时出错",this,i)}return c(this),!0}}return s}class _ extends l.EventBus{constructor(){super(...arguments);y(this,"refCount",0);y(this,"_isDestroyed",!1);y(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 c(this),!0}async destroy(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const r=this._destroyers[e];try{const t=r();t&&t instanceof Promise&&await t}catch(t){console.error("销毁函数在异步销毁时出错",this,r,t)}}this._destroyers.length=0;try{const r=this.destroyThis();r&&r instanceof Promise&&await r}catch(r){console.error("destroyThis 在异步销毁时出错",this,r)}return c(this),!0}}exports.Destroyable=d;exports.DestroyableEventTarget=_;exports.createDestroyableSubClass=D;exports.destroyDestroyable=c;exports.destroyObject=f;exports.throwOnDestroyed=h;