Closed Thread Icon

Topic awaiting preservation: Blocking script execution (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=8262" title="Pages that link to Topic awaiting preservation: Blocking script execution (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Blocking script execution <span class="small">(Page 1 of 1)</span>\

 
meccaman
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2002

posted posted 08-15-2002 20:43

I am trying to implement the following behavior:

while (something) {
openSomething();
waitUntilThatSomethingIsClosed();
nextSomething();
}

I tried using setTimeout to see if I could pause the execution for a set period of time as a test, however the loop execution continued anyway. Any one have any suggestions?

meccaman



[This message has been edited by meccaman (edited 08-15-2002).]

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-15-2002 23:39

var howManySeconds = 2;

function pause() {
myTimer=setTimeout("whatToDo()",howManySeconds*1000)
}

function whatToDo() {
window.location="http://www.gurusnetwork.com/";
}

is how I pause doing something (in this case, going to another page).

Dunno if this helps. I suspect not.



[This message has been edited by Pugzly (edited 08-15-2002).]

meccaman
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2002

posted posted 08-16-2002 01:13

Not exactly, but I'm always looking to learn something new.

I'm basically looking for sleep()/notify() behavior.

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 08-16-2002 15:36

I actually have a script where stopping an entire script dead in its tracks at a certain point would be quite handy. But I dont think you can do that , have and if(stopped) on key functions and then set notstopped to true to stop it doing anything. ( you'll have to stick in var stopped = 0; globally, of course ) Pugzly's trick works on setInterval aswell.

bitdamaged
Maniac (V) Mad Scientist

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

posted posted 08-16-2002 17:55

You can do this with a setTimeout loop something like so

// These has to be set here once since JS breaks if
// you try to run a conditional test on a un intialized variable.
var timer = false;
var flag = false;

//you can make your interval whatever it's in ms
interval = 1000

function sleep() {
if (flag) {
clearTimeout(timer);
nextSomething();
} else {
timer = setTimeout('sleep()', interval);
}
}

Now you can either set flag to true somewhere or stick someother test in there to see if that something is closed or whatever. This should kinda replicate perl's sleep function



.:[ Never resist a perfect moment ]:.

[This message has been edited by bitdamaged (edited 08-16-2002).]

meccaman
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2002

posted posted 08-17-2002 07:57

Thanks guys for the suggestions. I'll have to play around with them this weekend.
I'll let you know how it works out.

meccaman

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 08-17-2002 09:32

sleep() or alike does not exist in JavaScript!

what you can do is write a loop that makes some processing just to consume the desired delay of time.

meccaman
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2002

posted posted 08-20-2002 23:55

I got the functionality I'm looking for.

The logic goes something like this:

var globalArray;

doSomething(arr) {
if (arr) {
// Do the something

return;
}
// Otherwise, do nothing.
}

// This is called by an event in the something
handleUserEvent() {
doSomething(globalArray.pop());
}

To start things off I call doSomthing(globalArray.pop()), the param is an ID which is used to grab and show a record from the database. The user can view/manipulate the record and close the display generating an event that calls handleUserEvent. handleUserEvent calls doSomething and the process continues until the array is null.

Anyway, it works for what I'm trying to do. Thanks for all the inputs.

« BackwardsOnwards »

Show Forum Drop Down Menu