Javascript sleep, javascript wait, javascript setTimeout

When you are trying to call same ajax function again and again ,then it may be possible that some calls are not acknowledged.i experienced this problem so i’m sharing this article Javascript sleep, javascript wait, javascript setTimeout with you .

Sleep function  stops the executing thread for given amount of time.

for example:
we have function name

function do_ajax() {
//some code
}

if call it 4 times continuously then it may be possible that not all function calls acceptable.

to solve this problem you have to insert some pause or some time interval between two or more consecutive call.to do so you can introduce javascript delay between two calls.

LIKE:

do_ajax();
tea_break(500);
//sleep for 500 msec
do_ajax();

here is the javascript function you can name it coffeebreak, teabreak,   Javascript sleep, javascript wait, javascript setTimeout , javascript delay.

Javascript sleep, javascript wait, javascript setTimeout

function tea_break(msec) {
var date = new Date();
var curDate = null;
do {
curDate = new Date();
}
while(curDate - date < msec);
}

as shown in code it works on the current date/time and date/time  interval you choose

Live example of this function:

[do_widget id=text-5]
You can download the copy of this example.
Download

  • a

    Good article

  • a

    Good article