Skip to content

Instantly share code, notes, and snippets.

@dobriai
Last active October 5, 2017 03:19
Show Gist options
  • Save dobriai/a52c0f1dd2c9e89f0f8d6174e686a0de to your computer and use it in GitHub Desktop.
Save dobriai/a52c0f1dd2c9e89f0f8d6174e686a0de to your computer and use it in GitHub Desktop.
Promise timing
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
if (false) {
Promise
.resolve('One')
.then((xx) => { console.log(xx); });
} else {
(async () => {
console.log( await Promise.resolve('One') );
})();
}
console.log('Hey');
// Output:
// ---------------------------
// Hey
// One
(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