export async function getOrInsertAsync(map: Map, key: K, callback: (key: K) => Promise): Promise { if (map.has(key)) { return map.get(key)! } else { const value = await callback(key) map.set(key, value) return value } }