Created
February 11, 2018 16:58
-
-
Save darxtrix/eb4eda9fcdbc19cfc709b8b85f6c4e1c to your computer and use it in GitHub Desktop.
#nodejs #blocking_node #async #await
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
var p = (i) => { | |
return new Promise((resolve,reject) => { | |
setTimeout(() => { | |
resolve(i); | |
},1000); | |
}); | |
} | |
async function test() { | |
for (let i = 0; i < 2; i++) { | |
console.log('Before await for ', i); | |
let result = await p(i); | |
console.log('After await. Value is ', result); | |
} | |
console.log("cool hai"); | |
} | |
test().then(_ => console.log('After test() resolved')); | |
console.log('After calling test'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment