Skip to content

Instantly share code, notes, and snippets.

@darxtrix
Created February 11, 2018 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darxtrix/eb4eda9fcdbc19cfc709b8b85f6c4e1c to your computer and use it in GitHub Desktop.
Save darxtrix/eb4eda9fcdbc19cfc709b8b85f6c4e1c to your computer and use it in GitHub Desktop.
#nodejs #blocking_node #async #await
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