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);
} catch (error) {
console.log('Error:', error);
}
};
runtsk();
Top comments (0)