1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export class Disposable {
|
9 | static from(...inDisposables: { dispose(): any }[]): Disposable {
|
10 | let disposables: ReadonlyArray<{ dispose(): any }> | undefined = inDisposables;
|
11 | return new Disposable(function () {
|
12 | if (disposables) {
|
13 | for (const disposable of disposables) {
|
14 | if (disposable && typeof disposable.dispose === 'function') {
|
15 | disposable.dispose();
|
16 | }
|
17 | }
|
18 | disposables = undefined;
|
19 | }
|
20 | });
|
21 | }
|
22 |
|
23 | #callOnDispose?: () => any;
|
24 |
|
25 | constructor(callOnDispose: () => any) {
|
26 | this.#callOnDispose = callOnDispose;
|
27 | }
|
28 |
|
29 | dispose(): any {
|
30 | if (typeof this.#callOnDispose === 'function') {
|
31 | this.#callOnDispose();
|
32 | this.#callOnDispose = undefined;
|
33 | }
|
34 | }
|
35 | }
|