Last active
October 5, 2017 03:19
-
-
Save dobriai/a52c0f1dd2c9e89f0f8d6174e686a0de to your computer and use it in GitHub Desktop.
Promise timing
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
if (false) { | |
new Promise((resCB) => { | |
console.log('First Promise'); | |
resCB('p1'); | |
}).then(res => { | |
console.log(`res = ${res}`); | |
}) | |
} else { | |
(async () => { | |
let res = await new Promise((resCB) => { | |
console.log('First Promise'); | |
resCB('p1'); | |
}); | |
console.log(`res = ${res}`); | |
})(); | |
} | |
console.log('Hey!'); | |
// Output: | |
// --------------------------- | |
// First Promise | |
// Hey! | |
// res = p1 |
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
if (false) { | |
Promise | |
.resolve('One') | |
.then((xx) => { console.log(xx); }); | |
} else { | |
(async () => { | |
console.log( await Promise.resolve('One') ); | |
})(); | |
} | |
console.log('Hey'); | |
// Output: | |
// --------------------------- | |
// Hey | |
// One |
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 () => { | |
console.log(await 'One'); | |
})(); | |
console.log('Hey'); | |
// Output: | |
// --------------------------- | |
// Hey | |
// One |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment