I want to iterate the entries of a Map with an asynchronous callback function. The callback function should be started immediately for all elements.
I ended up with the following code, which works but looks too complicated:
async function test() {
const map1 = new Map();
map1.set('a', 1);
map1.set('b', 2);
map1.set('c', 3);
await Promise.all(Array.from(map1.entries()).map(async([
key,
value
]) => {
await doSomeThing(key, value);
await doSomeOtherThing(key, value);
}
}
Is there an easier way to achieve this?