CancellationTokenSource.dispose() should not cancel() (#46102)

* debt - dispose one CancellationTokenSource

* CancellationTokenSource.dispose() should not cancel()

fixes #46101

* CancellationToken.None when disposing
This commit is contained in:
Benjamin Pasero
2018-03-20 16:38:01 +01:00
committed by GitHub
parent bc8df86847
commit 6763e995fe
2 changed files with 17 additions and 4 deletions
+16 -3
View File
@@ -45,8 +45,7 @@ class MutableToken implements CancellationToken {
this._isCancelled = true;
if (this._emitter) {
this._emitter.fire(undefined);
this._emitter.dispose();
this._emitter = undefined;
this.dispose();
}
}
}
@@ -64,6 +63,13 @@ class MutableToken implements CancellationToken {
}
return this._emitter.event;
}
public dispose(): void {
if (this._emitter) {
this._emitter.dispose();
this._emitter = undefined;
}
}
}
export class CancellationTokenSource {
@@ -93,6 +99,13 @@ export class CancellationTokenSource {
}
dispose(): void {
this.cancel();
if (!this._token) {
// ensure to initialize with an empty token if we had none
this._token = CancellationToken.None;
} else if (this._token instanceof MutableToken) {
// actually dispose
this._token.dispose();
}
}
}
+1 -1
View File
@@ -1329,7 +1329,7 @@ declare module 'vscode' {
cancel(): void;
/**
* Dispose object and free resources. Will call [cancel](#CancellationTokenSource.cancel).
* Dispose object and free resources.
*/
dispose(): void;
}