Async,Await Promise
Anjali Gurjar

Anjali Gurjar @anjali_gurjar_dff81513867

About: I am Anjali Gurjar Work as Software Developer, I have total experience 4.5 .

Joined:
Dec 3, 2024

Async,Await Promise

Publish Date: Dec 17 '24
0 0

function asyncTask(delay, result) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(result);
}, delay);
});
}

const runtsk = async () => {
try {
const result = await Promise.all([
asyncTask(3000, 'first call'),
asyncTask(2000, 'second call'),
asyncTask(1000, 'third call')
]);

// Log the results of all the asynchronous tasks
console.log(result);
Enter fullscreen mode Exit fullscreen mode

} catch (error) {
console.log('Error:', error);
}
};

runtsk();

Comments 0 total

    Add comment