"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOrLoadPromiseCacheEntry = getOrLoadPromiseCacheEntry;
exports.getOrLoadPromiseCacheSlot = getOrLoadPromiseCacheSlot;
function getOrLoadPromiseCacheEntry(cache, key, loader) {
    const cached = cache.get(key);
    if (cached) {
        return cached;
    }
    const loaded = loader().catch((error) => {
        cache.delete(key);
        throw error;
    });
    cache.set(key, loaded);
    return loaded;
}
function getOrLoadPromiseCacheSlot(slot, loader) {
    const cached = slot.current;
    if (cached) {
        return cached;
    }
    const loaded = loader().catch((error) => {
        slot.current = null;
        throw error;
    });
    slot.current = loaded;
    return loaded;
}
