Created
January 4, 2022 15:33
-
-
Save onosendi/2b3e0511098ca9534108f2c42a1acbe7 to your computer and use it in GitHub Desktop.
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
function sleep(miliseconds = 1000) { | |
return new Promise((resolve) => setTimeout(resolve, miliseconds)); | |
} | |
// This will log 'foo' and 'bar' immediately. | |
async function foo1() { | |
console.log('foo'); | |
sleep(); | |
console.log('bar'); | |
} | |
// This will log 'foo', and 'bar' won't be logged until `sleep` is done. | |
// It's saying 'wait for this, then continue'. | |
async function foo2() { | |
console.log('foo'); | |
await sleep(); | |
console.log('bar'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment