Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small cleanup of dispose #162906

Merged
merged 2 commits into from Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/base/common/iterator.ts
Expand Up @@ -5,7 +5,7 @@

export namespace Iterable {

export function is<T = any>(thing: any): thing is IterableIterator<T> {
export function is<T = any>(thing: any): thing is Iterable<T> {
return thing && typeof thing === 'object' && typeof thing[Symbol.iterator] === 'function';
}

Expand Down
12 changes: 8 additions & 4 deletions src/vs/base/common/lifecycle.ts
Expand Up @@ -118,10 +118,10 @@ export function isDisposable<E extends object>(thing: E): thing is E & IDisposab

export function dispose<T extends IDisposable>(disposable: T): T;
export function dispose<T extends IDisposable>(disposable: T | undefined): T | undefined;
export function dispose<T extends IDisposable, A extends IterableIterator<T> = IterableIterator<T>>(disposables: IterableIterator<T>): A;
export function dispose<T extends IDisposable, A extends Iterable<T> = Iterable<T>>(disposables: A): A;
export function dispose<T extends IDisposable>(disposables: Array<T>): Array<T>;
export function dispose<T extends IDisposable>(disposables: ReadonlyArray<T>): ReadonlyArray<T>;
export function dispose<T extends IDisposable>(arg: T | IterableIterator<T> | undefined): any {
export function dispose<T extends IDisposable>(arg: T | Iterable<T> | undefined): any {
if (Iterable.is(arg)) {
const errors: any[] = [];

Expand Down Expand Up @@ -177,7 +177,7 @@ export class DisposableStore implements IDisposable {

static DISABLE_DISPOSED_WARNING = false;

private _toDispose = new Set<IDisposable>();
private readonly _toDispose = new Set<IDisposable>();
private _isDisposed = false;

constructor() {
Expand Down Expand Up @@ -210,8 +210,12 @@ export class DisposableStore implements IDisposable {
* Dispose of all registered disposables but do not mark this object as disposed.
*/
public clear(): void {
if (this._toDispose.size === 0) {
return;
}

try {
dispose(this._toDispose.values());
dispose(this._toDispose);
} finally {
this._toDispose.clear();
}
Expand Down