Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript sleep function

sleep = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));

//        V  Must add this async keyword
sayHi = async () => {
  	// V Must include await
	await sleep(1000); // Sleep 1000 milliseconds (1 second)
  	console.log('Hi');
  	// Rest of code...
}
Source by stickynotepickles.herokuapp.com #
 
PREVIOUS NEXT
Tagged: #javascript #sleep #function
ADD COMMENT
Topic
Name
7+5 =