Javascript – Simple async – await example

The following is a very simple async – await example:

// async - await example
async function example() {
    try {
        const data = await Promise.all([getdata1(), getdata2()]);   // will wait till the requests are completed
        processData(data);
    }
    catch (err) {
        console.error(err);
    }
}
 
const processData = (data) => {
    console.log('Data to process:', data);
}

Comments are closed.