- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- ソース を表示
- JavaScript/Promise/Promiseの実行 へ行く。
- 1 (2019-10-09 (水) 09:24:07)
- 2 (2019-10-09 (水) 09:29:52)
Promiseの実行
呼び出される非同期関数
function resolveAfter3Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 3000);
});
}
非同期関数の呼び出し 1 - Promise.then()
resolveAfter3Seconds().then((data) =>{
console.log(data);
});
非同期関数の呼び出し 2 - async/await
async function getAsyncData() {
const result = await resolveAfter3Seconds();
console.log(result);
}
getAsyncData();