"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__tsfTypeAliases = void 0;
exports.createSemaphore = createSemaphore;
exports.deferred = deferred;
const tslib_1 = require("tslib");
const _a = tslib_1.__importStar(require("@zyno-io/ts-server-foundation/type-metadata-runtime"));
function createSemaphore() {
    let released = false;
    let resolvePromise;
    const promise = new Promise(resolve => {
        resolvePromise = resolve;
    });
    return {
        promise,
        release() {
            if (released)
                throw new Error('Semaphore already released');
            released = true;
            queueMicrotask(resolvePromise);
        }
    };
}
function deferred() {
    let resolve;
    let reject;
    const promise = new Promise((resolve_, reject_) => {
        resolve = resolve_;
        reject = reject_;
    });
    return { promise, resolve, reject };
}
exports.__tsfTypeAliases = _a.decodeCompactMetadataV1("[1,{\"Semaphore\":{\"kind\":18,\"typeName\":\"Semaphore\",\"types\":[{\"kind\":20,\"name\":\"promise\",\"type\":{\"kind\":22,\"type\":{\"kind\":3}},\"optional\":false}]}}]", []);
//# sourceMappingURL=promise.js.map