Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js sleep

//Sleep funktion

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
//Or as a one-liner:

await new Promise(r => setTimeout(r, 2000));
//As a function:

const sleep = ms => new Promise(r => setTimeout(r, ms));
//or in Typescript:

const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
//use it as:

await sleep(<duration>);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #sleep
ADD COMMENT
Topic
Name
8+7 =