Created
June 6, 2017 05:20
-
-
Save tomalex0/87c2a06500046b84ad74fefd51cc26a5 to your computer and use it in GitHub Desktop.
Async Await Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function read1 () { | |
var firstName = "Thomas"; | |
console.log(firstName,'read1'); | |
return firstName; | |
} | |
async function read2 () { | |
var firstName = await read1(); | |
var lastName = "Alexander"; | |
var fullName = `${firstName} ${lastName}` | |
console.log(fullName,'read2'); | |
return fullName; | |
} | |
async function asyncFun () { | |
var fullName = await read2(); | |
var value = await Promise | |
.resolve(1) | |
.then(x => x * 3) | |
.then(x => x + 5) | |
.then(x => x / 2); | |
return `${value} - ${fullName}`; | |
} | |
asyncFun().then(x => console.log(`x: ${x}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment