Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
js sleep
function sleep(ms){
return new Promise((resolve)=>setTimeout(resolve,ms));
}
async function test(){
var temple=await sleep(1000);
console.log(1111)
return temple
}
test();
// 利用循环
function sleep(d){
for(var t = Date.now() ; Date.now()-t <= d ;)
{
continue;
}
}
function* sleep(ms){
yield new Promise(function(resolve,reject){
console.log(111);
setTimeout(resolve,ms);
})
}
sleep(500).next().value.then(()=>{
console.log(11111)
})
var sleep = require('sleep');
var n=10;
sleep.sleep(n) //sleep for n seconds
sleep.msleep(n) //sleep for n miliseconds
sleep.usleep(n) //sleep for n microseconds (1 second is 1000000 microseconds)
function sleep(ms) {
return new Promise(resolve =>
setTimeout(resolve, ms)
)
}
sleep(3000).then(()=>{
//code
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment