Closed Thread Icon

Topic awaiting preservation: sleep Pages that link to <a href="https://ozoneasylum.com/backlink?for=8498" title="Pages that link to Topic awaiting preservation: sleep" rel="nofollow" >Topic awaiting preservation: sleep\

 
Author Thread
Koenie
Nervous Wreck (II) Inmate

From: Leiden, the Netherlands
Insane since: Dec 2002

posted posted 01-28-2003 21:37

I've been working with JavaScript and Java for a while now, and I'm beginning to miss some things I use in Java, but don't know how to do with JavaScript.

The particular problem in this case is I miss the Thread.sleep() method. For people who don't know Java, Thread.sleep() stops the process for a while and then just continues where is paused. I tried to do something like this with setInterval() and setTimeout() but it does not seem to work.
Does anyone know wether this is possible, and if yes: please tell me!

Thanks in advance,
Koenie

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-28-2003 22:53

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.

Koenie
Nervous Wreck (II) Inmate

From: Leiden, the Netherlands
Insane since: Dec 2002

posted posted 01-29-2003 21:09

what I'm trying to do, is making a function sleep for a while before it goes on. Like this:

code:
function myFunkyFunction(myPansyParameter) {
// do some funky things
sleep(2000); // wait for 2 seconds
// do some pansy things
}



Koenie

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 01-29-2003 21:33

You can't do that as simply as you want to. You'll have to do it like this:

function foo()
{
// do stuff
setTimeout('bar()', 1000) // 1 second, call "bar" function
// anything here will be executed without waiting, before bar is called
}

function bar()
{
// do stuff
}

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 01-29-2003 22:59

var thread = 0;

function start() {
thread = setInterval("pants()",2000);
}

function sleep(duration) {
if(thread)clearTimout(thread);
if(duration)setTimeout("start()",duration);
}

This should work similar to what your used to in Java, it'll only work on the one thread, I couldnt have been bothered writing it all in eval()s or something to accomodate many threads. run sleep(2000) to pause the thread for 2 seconds. Running sleep with no duration will function like a stop() command. To run thread in x amount of seconds, you can run it with sleep(x);



[This message has been edited by Hugh (edited 01-30-2003).]

Koenie
Nervous Wreck (II) Inmate

From: Leiden, the Netherlands
Insane since: Dec 2002

posted posted 01-30-2003 13:53

Will that code work just like I meant to make it work in the code example?

Koenie

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-30-2003 17:58

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.

Koenie
Nervous Wreck (II) Inmate

From: Leiden, the Netherlands
Insane since: Dec 2002

posted posted 01-30-2003 20:53

ok, sorry, Sorry, SORRY!!!!! I didn't mean it this way! I was at school when I wrote that, and the computers are quite crappy there. I WILL try it. Million apologees. Sorry.

Sorry, Koenie

« BackwardsOnwards »

Show Forum Drop Down Menu