Async Await

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function asyncFunc() {
return new Promise((res,rej) => {
setTimeout(() => {
res("helloWorld");
}, 5000)
})
}
async function runAsync() {
let helloWorld = await asyncFunc();
console.log(helloWorld);
}
runAsync();

In 5 seconds, the helloWorld variable will log to the console. Its value will be the resolve of the promise.

1
"helloWorld"
© 2017 CompuDharma Blog All Rights Reserved.
Theme by hiero