Merge branch 'master' into show-extension-preferences-in-separate-page

This commit is contained in:
Alex Andreev committed 2022-04-29 14:52:52 +03:00
commit 00efcad5ee
39 files changed
+2567 -1789

No files matched your search

+11
View File
@@ -48,6 +48,17 @@ export function getOrInsertWith<K, V>(map: Map<K, V>, key: K, builder: () => V):
return map.get(key);
}
/**
* Like {@link getOrInsertWith} but the builder is async and will be awaited before inserting into the map
*/
export async function getOrInsertWithAsync<K, V>(map: Map<K, V>, key: K, asyncBuilder: () => Promise<V>): Promise<V> {
if (!map.has(key)) {
map.set(key, await asyncBuilder());
}
return map.get(key);
}
/**
* Set the value associated with `key` iff there was not a previous value
* @param map The map to interact with