MCPcopy
hub / github.com/xtermjs/xterm.js / MutableDisposable

Class MutableDisposable

src/vs/base/common/lifecycle.ts:507–557  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

505 * also register a `MutableDisposable` on a `Disposable` to ensure it is automatically cleaned up.
506 */
507export class MutableDisposable<T extends IDisposable> implements IDisposable {
508 private _value?: T;
509 private _isDisposed = false;
510
511 constructor() {
512 trackDisposable(this);
513 }
514
515 get value(): T | undefined {
516 return this._isDisposed ? undefined : this._value;
517 }
518
519 set value(value: T | undefined) {
520 if (this._isDisposed || value === this._value) {
521 return;
522 }
523
524 this._value?.dispose();
525 if (value) {
526 setParentOfDisposable(value, this);
527 }
528 this._value = value;
529 }
530
531 /**
532 * Resets the stored value and disposed of the previously stored value.
533 */
534 clear(): void {
535 this.value = undefined;
536 }
537
538 dispose(): void {
539 this._isDisposed = true;
540 markAsDisposed(this);
541 this._value?.dispose();
542 this._value = undefined;
543 }
544
545 /**
546 * Clears the value, but does not dispose it.
547 * The old value is returned.
548 */
549 clearAndLeak(): T | undefined {
550 const oldValue = this._value;
551 this._value = undefined;
552 if (oldValue) {
553 setParentOfDisposable(oldValue, null);
554 }
555 return oldValue;
556 }
557}
558
559/**
560 * Manages the lifecycle of a disposable value that may be changed like {@link MutableDisposable}, but the value must

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected