Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sleep javascript

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function demo() {
    for (let i = 0; i < 5; i++) {
        console.log(`Waiting ${i} seconds...`);
        await sleep(i * 1000);
    }
    console.log('Done');
}

demo();
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sleep #javascript
ADD COMMENT
Topic
Name
8+9 =