console.log('Start')
function resolveAfter2Seconds() {
return new Promise(resolve => {
// setTimeout(() => { resolve('resolved') }, 2000);
for (let index = 0; index < 1000000000; index++) { }
resolve('resolved !');
})
};
async function asyncCall() {
console.log('calling');
const result = await resolveAfter2Seconds();
console.log(result);
}
asyncCall();
console.log('End');
Return:
Start
calling
End
resolved !
I have the impression that promises handle callbacks better !
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…