Parallel Promises

Very basic example of how to do parallel promises.

function task (name) {
    console.info(`Running "${name}"`);
    
    return new Promise(resolve => {
        let wait = Math.round(Math.random() * 1000);
    
        setTimeout(() => {
            console.info(`Completed "${name}" in ${wait} ms`);
            resolve();
        }, wait);
    });
}

async function multiTasks () {
    let task1 = task("1"),
        task2 = task("2");
        
    await task1;
    await task2;
    
    console.info("All done");
}

async function multiTasks2 () {
    let tasks = Promise.all([task("3"), task("4")]);
        
    await tasks;
    
    console.info("All done");
}

multiTasks();
multiTasks2();

await Promise.all(items.map(async (item) => { 
  await fetchItem(item) 
}))

Resources