async function
async function asyncFunc1(){
return 42;
}
asyncFunc1()
.then(function(response){
output.innerText = response;
})
promise in async
async function asyncFunc2(){
let innerPromise2 = new Promise(
function(res, rej){
setTimeout(function(){
res("promise 2 result");
}, 2000); // 2 seconds
}
);
return innerPromise2;
}
asyncFunc2()
.then(function(response){
output.innerText = response; // resolve
})
await in async
async function asyncFunc3(){
let innerPromise3 = new Promise(
function(res, rej){
setTimeout(function(){
res("promise 3 result");
}, 2000); // 2 seconds
}
);
let result = await innerPromise3;
output.innerText = result; // resolve
}
asyncFunc3();