Move to MutableDisposable in vs
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* http://linux.die.net/man/7/urxvt
|
||||
*/
|
||||
|
||||
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
|
||||
import { Disposable, toDisposable } from 'common/Lifecycle';
|
||||
import { IInstantiationService, IOptionsService, IBufferService, ILogService, ICharsetService, ICoreService, ICoreMouseService, IUnicodeService, LogLevelEnum, ITerminalOptions, IOscLinkService } from 'common/services/Services';
|
||||
import { InstantiationService } from 'common/services/InstantiationService';
|
||||
import { LogService } from 'common/services/LogService';
|
||||
@@ -39,6 +39,7 @@ import { InputHandler } from 'common/InputHandler';
|
||||
import { WriteBuffer } from 'common/input/WriteBuffer';
|
||||
import { OscLinkService } from 'common/services/OscLinkService';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { MutableDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
// Only trigger this warning a single time per session
|
||||
let hasWriteSyncWarnHappened = false;
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
*/
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { Disposable, MutableDisposable } from 'common/Lifecycle';
|
||||
import { IDisposable } from 'common/Types';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
|
||||
class TestDisposable extends Disposable {
|
||||
public get isDisposed(): boolean {
|
||||
@@ -44,52 +43,3 @@ describe('Disposable', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('MutableDisposable', () => {
|
||||
const mutable = new MutableDisposable();
|
||||
class TrackedDisposable extends Disposable {
|
||||
public get isDisposed(): boolean { return this._isDisposed; }
|
||||
}
|
||||
describe('value', () => {
|
||||
it('should set the value', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
assert.strictEqual(mutable.value, d1);
|
||||
assert.isFalse(d1.isDisposed);
|
||||
});
|
||||
it('should dispose of any previous value', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
const d2 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
mutable.value = d2;
|
||||
assert.strictEqual(mutable.value, d2);
|
||||
assert.isTrue(d1.isDisposed);
|
||||
assert.isFalse(d2.isDisposed);
|
||||
});
|
||||
});
|
||||
describe('clear', () => {
|
||||
it('should clear and dispose of the object', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
mutable.clear();
|
||||
assert.strictEqual(mutable.value, undefined);
|
||||
assert.isTrue(d1.isDisposed);
|
||||
});
|
||||
});
|
||||
it('dispose', () => {
|
||||
it('should dispose of the object', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
mutable.dispose();
|
||||
assert.strictEqual(mutable.value, undefined);
|
||||
assert.isTrue(d1.isDisposed);
|
||||
});
|
||||
it('should prevent using the MutableDisposable again', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
mutable.dispose();
|
||||
mutable.value = new TrackedDisposable();
|
||||
assert.strictEqual(mutable.value, undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,42 +47,6 @@ export abstract class Disposable implements IDisposable {
|
||||
}
|
||||
}
|
||||
|
||||
export class MutableDisposable<T extends IDisposable> implements IDisposable {
|
||||
private _value?: T;
|
||||
private _isDisposed = false;
|
||||
|
||||
/**
|
||||
* Gets the value if it exists.
|
||||
*/
|
||||
public get value(): T | undefined {
|
||||
return this._isDisposed ? undefined : this._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value, disposing of the old value if it exists.
|
||||
*/
|
||||
public set value(value: T | undefined) {
|
||||
if (this._isDisposed || value === this._value) {
|
||||
return;
|
||||
}
|
||||
this._value?.dispose();
|
||||
this._value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the stored value and disposes of the previously stored value.
|
||||
*/
|
||||
public clear(): void {
|
||||
this.value = undefined;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this._isDisposed = true;
|
||||
this._value?.dispose();
|
||||
this._value = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a function in a disposable.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user