Last active
May 8, 2020 14:58
-
-
Save slmyers/fdf5a278dfadeb86011b4bf3a60f2b41 to your computer and use it in GitHub Desktop.
exchange js gists 5/7/2020, for a game
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
// adds a function to the microtask queue, will not print anything this tick | |
Promise.resolve().then(() => console.log(2)) | |
// this will execute on the current phase of the event loop | |
console.log(1) |
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
// synchronous execution | |
console.log(1) | |
// ?? I would expect this last | |
await Promise.reject().catch(() => console.log(2)) | |
// ?? I would expect this third | |
Promise.resolve().then(() => console.log(4)) | |
// new Promise is synchronous, but I would expect this before `2` | |
new Promise((resolve, reject) => { | |
resolve() | |
console.log(3) | |
}) |
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
// new Promise is synchronous await doesn't impede execution? | |
await new Promise((res, rej) => { | |
console.log(1) | |
res() | |
console.log(2) | |
}) | |
// ?? I would expect this to be 4 | |
await Promise.resolve().then(() => console.log(3)) | |
// ?? I thought this would be 3 | |
await (console.log(4)) |
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
// 1 and 2 are executed in the order they're encountered | |
await new Promise((res, rej) => rej()).catch(() => console.log(1)) | |
try { | |
await Promise.reject() | |
} catch (e) { | |
console.log(2) | |
} | |
// await blocks execution so this happens last | |
console.log(3) |
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
// sync | |
new Promise((res, rej) => rej()).catch(() => console.log(1)) | |
try { | |
// Uncaught (in promise) | |
Promise.reject() | |
} catch (e) { | |
console.log("NEVER") | |
} | |
// sync | |
console.log(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment