DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Javascript - Sleep

07.06.2006
| 37965 views |
  • submit to reddit
        // Effettuare uno sleep dello script di uno script

function pause(millisecondi)
{
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;

    while(true)
    {
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}
    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:25pm

Horrible approach =/

Snippets Manager replied on Fri, 2006/07/07 - 11:59pm

This code must not be used, it is a bad practice. It is completly freezing the client and as a result, you can't correctly manage events in same time. The only way is to use a timeout.