"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Creates a react suspense compatible wrapper for a loading value
 *
 * Call read to either get the value, once its loaded, or to trigger a suspense boundary in case its not yet available.
 *
 * @template T
 * @param {Promise<T>} promise
 * @returns {Suspender<T>}
 */
exports.createSuspender = function (promise) {
    var status = "pending";
    var value;
    var error;
    promise
        .then(function (data) {
        status = "resolved";
        value = data;
    })
        .catch(function (err) {
        status = "rejected";
        error = err;
    });
    return {
        read: function () {
            switch (status) {
                case "pending":
                    throw promise;
                case "rejected":
                    throw error;
                case "resolved":
                    return value;
            }
        },
    };
};
