From 777453f5e93adb1220b6f106a9ed58a08209d0fb Mon Sep 17 00:00:00 2001 From: LSvekis Date: Fri, 1 Oct 2021 12:22:17 -0400 Subject: [PATCH] Create async await --- Chapter 12/async await | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Chapter 12/async await diff --git a/Chapter 12/async await b/Chapter 12/async await new file mode 100644 index 0000000..2dbb25b --- /dev/null +++ b/Chapter 12/async await @@ -0,0 +1,17 @@ + let cnt = 0; + function outputTime(val) { + return new Promise(resolve => { + setTimeout(() => { + cnt++; + resolve(`x value ${val} counter:${cnt}`); + }, 1000); + }); + } + async function aCall(val) { + console.log(`ready ${val} counter:${cnt}`); + const res = await outputTime(val); + console.log(res); + } + for (let x = 1; x < 4; x++) { + aCall(x); + }