sleeping in js
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
/*Use like so*/
async function timeSensativeAction(){ //must be async func
//do something here
await sleep(5000) //wait 5 seconds
//continue on...
}function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
//using sleep()
sleep(2000); //sleep for 2 seconds
Also in JavaScript:
- how to add oAuth google signin in react native app
- javascript detect touch screen device
- javascript less than but greater than
- javascript detect textarea change
- install node js 14
- javascript remover acentos
- discord js check every x minutes
- react redux
- javascript document load
- Javascript track mouse pointer
- multiple conditions for JavaScript .includes() method
- javascript founder
- get today date and time in js
- javascript check if text is overflowing
- document ready js
- set cookie javascript
- node js mysql escape string
- how to change list item text color in react
- setting property to method in child class javascript
- position of the mouse cursor javascript
- ionic ngfor in component
- javascript template string
- synchronous vs asynchronous functions javascript
- react native routes