Preventing Simultaneous Functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kid

    Preventing Simultaneous Functions

    I need help with a page i'm coding which has several functions to
    dynamically change the display. Everything works fine but the problem
    is that I need to have the final function wait for all others to
    finish before it resets certain onscreen buttons and then returns.I'm
    having trouble implementing this efficiently and would greatly
    appreciate any help/comments.
  • Thomas 'PointedEars' Lahn

    #2
    Re: Preventing Simultaneous Functions

    kid wrote:
    [color=blue]
    > I need help with a page i'm coding which has several functions to
    > dynamically change the display. Everything works fine but the problem
    > is that I need to have the final function wait for all others to
    > finish before it resets certain onscreen buttons and then returns.I'm
    > having trouble implementing this efficiently and would greatly
    > appreciate any help/comments.[/color]

    Post *relevant snippets* of your code or the URI
    of a test case and we will see what can be done.


    PointedEars

    Comment

    • Brian Genisio

      #3
      Re: Preventing Simultaneous Functions

      kid wrote:[color=blue]
      > I need help with a page i'm coding which has several functions to
      > dynamically change the display. Everything works fine but the problem
      > is that I need to have the final function wait for all others to
      > finish before it resets certain onscreen buttons and then returns.I'm
      > having trouble implementing this efficiently and would greatly
      > appreciate any help/comments.[/color]

      Yeah... what Thomas said... except, here is a basic outline of something
      you might want to try... untested, but it should help out. If you show
      more, we can help more.

      First of all, I am assuming you must be using something like setTimeout
      on all of your functions to execute. This assumption is based off the
      fact that Javascript executes serially in all browsers I know about.
      This means that you should know when a script is done, unless you are
      setting events (via setTimeout or setInterval).

      Ok, making that assumption, think about this:

      /////////////////////////////////////////////////////////////////
      var func1_done = false;
      var func2_done = false;
      var func3_done = false;

      function func1() {
      //... code
      func1_done = true;
      }

      function func2() {
      //... do someting
      func2_done = true;
      }

      function func3() {
      //... do something
      func3_done = true;
      }

      function checkForDone() {
      if( func1_done && func2_done && func3_done )
      {
      // Do what you need to do... all three are done
      }
      else
      setTimeout("che ckForDone()", 500); // check again in 1/2 sec
      }
      /////////////////////////////////////////////////////////////////

      Then, you can run checkForDone, when you want to execute your code. It
      will only execute if 1, 2 and 3 are done. If not, it will try again in
      half of a second (change this to whatever you think is necessary)

      Also, for good programming practices, use an array for the funcN_done
      flags, if you have more than three functions to worry about.

      Brian


      Comment

      Working...