Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
The cleanest JavaScript sleep() function
node v4.9.1
version:
master
endpoint
share
tweet
Implementing sleep(milliseconds) with async/await
function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } console.log('Taking a break...'); await sleep(2000); console.log('Two seconds later'); // Click the ⟳ icon to the right =========>
Loading…
no comments
sign in
to comment