Slide 10
Slide 10 text
async awaitを利用しない場合
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
console.log('resolved');
resolve();
}, 2000);
});
}
function asyncCall() {
return new Promise(resolve => {
console.log('calling');
resolveAfter2Seconds().then(() => {
console.log('called');
});
});
}
asyncCall(); // 非同期関数
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
console.log('resolved');
resolve();
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
await resolveAfter2Seconds();
console.log('called');
}
asyncCall(); // 非同期関数
async awaitによってシンプルな構文になる
(糖衣構文)