Home >Web Front-end >JS Tutorial >Async,Await Promise
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();
The above is the detailed content of Async,Await Promise. For more information, please follow other related articles on the PHP Chinese website!