Async/Await サンプル2- JavaScript
by s_hiroshi
JavaScript
/*
* async/awaitサンプル
*
* 直列処理で1秒間隔で2回日付を表示します。
* 別サンプルで下記URLも参照してください。
* https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/async_function
*/
function nowTime() {
return new Promise(resolve => {
window.setTimeout(
function() {
console.log("Time: " + new Date().toString());
resolve();
},
1000);
});
}
async function showTime() {
await nowTime();
await nowTime();
}
// ここから実行
showTime();