/**
 * Async counting semaphore for limiting concurrent operations.
 * Used by VerificationHarness to prevent resource exhaustion when
 * multiple goals verify simultaneously.
 */
export class Semaphore {
    _value;
    _capacity;
    _waiters = [];
    constructor(initial) {
        this._value = initial;
        this._capacity = initial;
    }
    get available() { return this._value; }
    get waiting() { return this._waiters.length; }
    async acquire() {
        if (this._value > 0) {
            this._value--;
            return;
        }
        return new Promise(resolve => {
            this._waiters.push(resolve);
        });
    }
    release() {
        const next = this._waiters.shift();
        if (next) {
            next();
        }
        else {
            if (this._value >= this._capacity) {
                throw new Error(`Semaphore over-release: value would exceed capacity (${this._capacity})`);
            }
            this._value++;
        }
    }
}
//# sourceMappingURL=semaphore.js.map