// src/concurrency.ts
var Mutex = class {
  locked = false;
  waiters = [];
  async acquire() {
    if (!this.locked) {
      this.locked = true;
      return () => this.release();
    }
    return new Promise((resolve) => {
      this.waiters.push(() => {
        resolve(() => this.release());
      });
    });
  }
  release() {
    const next = this.waiters.shift();
    if (next) {
      next();
    } else {
      this.locked = false;
    }
  }
  async runExclusive(fn) {
    const release = await this.acquire();
    try {
      return await fn();
    } finally {
      release();
    }
  }
  /** True iff someone holds the lock right now. Diagnostics only. */
  get isLocked() {
    return this.locked;
  }
  /** Pending waiter count. Diagnostics only. */
  get pending() {
    return this.waiters.length;
  }
};

export {
  Mutex
};
//# sourceMappingURL=chunk-3YYRZDON.js.map