node sleep
async function init() {
console.log(1);
await sleep(1000);
console.log(2);
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
// one liner
await new Promise(resolve => setTimeout(resolve, 5000));await new Promise(r => setTimeout(r, 2000));await sleep(1000)
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
Also in JavaScript:
- how to create monorapo project in angular 8
- Function used to reload the portion of a page using javascript
- parse date from string in js
- set element at index javascript array and create new array
- new fabric canvas set width
- uninstall node package
- jquery toggle show hide
- delete an item from array javascript
- javascript largest number in array
- how to run commands in the command prompt using javascript
- foreach in the elements with a data attibute jquery
- local storage javascript array
- jquery ajax
- json decoding and optionals
- js scrolling in div
- node filesystem change directory of a file
- how to delete the last part of a string in node js
- pick random string from array javascript
- get size of json object
- Who invented Yhe Javascript Programmming Language
- how to update value in nested json using id in javascript
- contact form7 404 wp-json feedback
- how to Check if an array contains a string
- jest cross origin localhost fobbiden