import { logError } from "../logger.js";
export class ADisposable {
  toDispose = [];
  isDisposed = false;
  onDispose(...disposable) {
    this.toDispose.push(...disposable);
  }
  dispose() {
    this.throwIfDisposed();
    this.isDisposed = true;
    let item;
    while (item = this.toDispose.pop()) {
      try {
        item.dispose();
      } catch (e) {
        logError(e);
      }
    }
  }
  throwIfDisposed() {
    if (this.isDisposed) {
      throw new Error("This has already been disposed");
    }
  }
}
