Skip to content

Instantly share code, notes, and snippets.

@tomalex0
Created June 6, 2017 05:20
Show Gist options
  • Save tomalex0/87c2a06500046b84ad74fefd51cc26a5 to your computer and use it in GitHub Desktop.
Save tomalex0/87c2a06500046b84ad74fefd51cc26a5 to your computer and use it in GitHub Desktop.
Async Await Test
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