www.webdeveloper.com
Results 1 to 3 of 3

Thread: SetTimeout issue

  1. #1
    Join Date
    Feb 2003
    Location
    London
    Posts
    9

    SetTimeout issue

    Hi,

    I have a function that calls itself using setTimeout('function1', 100) 90 times. Within this function, if a certain condition is true it calls another function which also has a setTimeout('function2' 200), I want this one to run 6 times, but while it is running the main looped function carries on executing. I want the main function to stop until function2 has run through it's 6 times.

    Anyone have any ideas?

    Cheers,
    C

  2. #2
    Join Date
    Apr 2003
    Location
    Detroit
    Posts
    272
    if you're trying to get the MAIN loop to suspend until all the other parts are done, dave's code is a good start


    but you need two globa variables firststatus = false
    and secondstatus = false

    then in your main loop after you call function 1 put a

    whie(!firststatus && !secondstatus){
    }

    now all you need to do is in dave's functions set the sentinels to true (meaning complete)


    if (some condition is true) {
    secondstatus = false;
    secondFunction();
    }
    if (counter1 < 90) {
    setTimeout("firstFunction()",100);
    }
    else {
    firststatus = true;
    }



    if (counter2 < 6) {
    secondstatus=false;
    setTimeout("secondFunction()",200);
    }
    else{
    secondstatus=true;
    }


    that shoudl work in most cases, but of course if you're calling a bunch of functions2's and they stop at weird intervals, it may fail. You'd have to work on security
    i am just a new boy, a stranger in this town. Where are all the good times, whose gonna show this stranger around.

    My Life & Less

  3. #3
    Join Date
    Apr 2003
    Location
    Detroit
    Posts
    272
    I reread what he was talking about, and i was wrong, sorry. I was thinking he wanted the main loop (i'm thinking c here) when he was talking about function1 loop (but said main).
    i am just a new boy, a stranger in this town. Where are all the good times, whose gonna show this stranger around.

    My Life & Less

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles