Closed Thread Icon

Preserved Topic: Does JavaScript sleep ? Pages that link to <a href="https://ozoneasylum.com/backlink?for=18110" title="Pages that link to Preserved Topic: Does JavaScript sleep ?" rel="nofollow" >Preserved Topic: Does JavaScript sleep ?\

 
Author Thread
lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 08-29-2001 11:48

I wonder of JavaScript have a function like Win32's API sleep() or PHP's sleep() or Old TP' Delay() ?

<script language="JavaScript">
<!--
var _secs, _max, _abort = false;

function _inc_secs()
{
if (_secs < _max)
setTimeout('_inc_secs()', 1000);
else
_abort = true;
_secs++;
status = _secs;
}

function _delay(secs)
{
_secs = 0;
_abort = false;
_max = secs / 1000;
while (!_abort) ;
_inc_secs();
}

_delay(5000);
alert('returned from a 5 secs delay');

//-->
</script>
This didn't work at all!
It seems that the 'while (!_abort)' line is beeing executed 100000 times a sec...before even one second elapse in the setTimeout().

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 08-29-2001 15:17

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-29-2001 16:40

JavaScript is event driven. Use setTimeout if you want a delay.

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 08-29-2001 19:28

ZZZZZZZZzzzzzzzzzzzzzz

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 08-29-2001 22:23

I'm wondering what you need to do that just using setTimeout() or setInterval() won't do? They allow you to define a function that for all intents and purposes, sleeps. Maybe I'm missing something?

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 08-29-2001 23:01

Bugmis, nice logo btw! It reminds me of the Cockroaches in "The Mummy" movies

Anyway, I want a Sleep() like function to run my code in a straight way and not completly event driven.

ie:
line1:
2:
3:sleep(5000); // wait n secs and proceed to next lines
4:
5:

so basically to have a straight code flow.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-29-2001 23:11

That's setTimeout

usage

variable = setTimeout('code to execute usually a function', 'time in milleseconds');

You don't need to name the function but it allows you to clear a Timeout if need be




:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 08-29-2001 23:11

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

« BackwardsOnwards »

Show Forum Drop Down Menu