export class AsyncLock {
    #tail = Promise.resolve();
    async runExclusive(operation) {
        const previous = this.#tail;
        let release;
        this.#tail = new Promise((resolve) => {
            release = resolve;
        });
        await previous;
        try {
            return await operation();
        }
        finally {
            release();
        }
    }
}
