import {apiRequestCache} from "./cacheManager"; import {LogLevel, logWithLevel} from "./logLevel"; export function checkAllRequestsComplete(): true | (string[]) { const cacheEntries = Array.from(apiRequestCache.values()) const stillRunning = cacheEntries.filter((cache) => undefined === cache.response) if (stillRunning.length !== 0) { if (typeof document === "undefined" || document === null) { throw new Error('document is undefined while waiting for API requests to complete (' + JSON.stringify(cacheEntries) + ')') } // when requests return emtpy sets in full renders, it may not be possible to track their progress. logWithLevel(LogLevel.WARN, undefined, console.warn, 'stillRunning...', stillRunning); return stillRunning.map((cache) => cache.requestArgumentsSerialized) } return true }