Skip to content

Instantly share code, notes, and snippets.

@mvictorl
Created October 1, 2020 07:54
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 mvictorl/6fedb1d17980f9a4162184a899de7098 to your computer and use it in GitHub Desktop.
Save mvictorl/6fedb1d17980f9a4162184a899de7098 to your computer and use it in GitHub Desktop.
JS function sleep() vice setTimeout() [return Promise]
const sleep = ms => {
return new Promise(resolve => {
setTimeout(() => resolve(), ms)
})
}
sleep(3000).then(() => console.log('After 3 seconds...'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment