"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createFulfilledPromise = createFulfilledPromise;
exports.createRejectedPromise = createRejectedPromise;
exports.isStatefulPromise = isStatefulPromise;
exports.wrapPromiseWithState = wrapPromiseWithState;
function createFulfilledPromise(value) {
    const promise = Promise.resolve(value);
    promise.status = "fulfilled";
    promise.value = value;
    return promise;
}
function createRejectedPromise(reason) {
    const promise = Promise.reject(reason);
    // prevent potential edge cases leaking unhandled error rejections
    promise.catch(() => { });
    promise.status = "rejected";
    promise.reason = reason;
    return promise;
}
function isStatefulPromise(promise) {
    return "status" in promise;
}
function wrapPromiseWithState(promise) {
    if (isStatefulPromise(promise)) {
        return promise;
    }
    const pendingPromise = promise;
    pendingPromise.status = "pending";
    pendingPromise.then((value) => {
        if (pendingPromise.status === "pending") {
            const fulfilledPromise = pendingPromise;
            fulfilledPromise.status = "fulfilled";
            fulfilledPromise.value = value;
        }
    }, (reason) => {
        if (pendingPromise.status === "pending") {
            const rejectedPromise = pendingPromise;
            rejectedPromise.status = "rejected";
            rejectedPromise.reason = reason;
        }
    });
    return promise;
}
//# sourceMappingURL=decoration.cjs.map
