Skip to content

Instantly share code, notes, and snippets.

@amironov73
Created March 13, 2019 11:21
Show Gist options
  • Select an option

  • Save amironov73/dfc968056bce78de4cd82792d612a810 to your computer and use it in GitHub Desktop.

Select an option

Save amironov73/dfc968056bce78de4cd82792d612a810 to your computer and use it in GitHub Desktop.
JavaScript async/await
async function first() {
console.log('First');
return 1;
}
async function second() {
console.log('Second/1');
const result1 = await first();
console.log('Second/2');
return result1 + 1;
}
async function third() {
console.log('Third/1');
const result2 = await second();
console.log('Third/2');
return result2 + 1;
}
(async () => {
console.log('Top/1');
const result3 = await third();
console.log('Result is ' + result3);
console.log('Top/2');
})().then(() =>
{
console.log('Top/3');
});
@amironov73
Copy link
Author

Prints:

Top/1
Third/1
Second/1
First
Second/2
Third/2
Result is 3
Top/2
Top/3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment