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

  • submit to reddit
        // Effettuare uno sleep dello script di uno script

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

        now = new Date();
        if(now.getTime() > exitTime) return;


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

Horrible approach =/

Snippets Manager replied on Fri, 2006/07/07 - 10: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.