forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlifecycle.ts
More file actions
54 lines (44 loc) · 1.4 KB
/
Copy pathlifecycle.ts
File metadata and controls
54 lines (44 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
export function toDisposable(d: () => void): vscode.Disposable {
return { dispose: d };
}
export function combinedDisposable(disposables: vscode.Disposable[]): vscode.Disposable {
return toDisposable(() => disposeAll(disposables));
}
export function disposeAll(disposables: vscode.Disposable[]) {
while (disposables.length) {
const item = disposables.pop();
item?.dispose();
}
}
export function addDisposable<T extends vscode.Disposable>(a: T, disposables: vscode.Disposable[]): T {
disposables.push(a);
return a;
}
export abstract class Disposable {
protected _isDisposed = false;
private _disposables: vscode.Disposable[] = [];
public dispose(): any {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
disposeAll(this._disposables);
this._disposables = [];
}
protected _register<T extends vscode.Disposable>(value: T): T {
if (this._isDisposed) {
value.dispose();
} else {
this._disposables.push(value);
}
return value;
}
protected get isDisposed() {
return this._isDisposed;
}
}