You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • There is no such thing as a generic wait function. If you have done something and you want to wait for example for a minute before doing something else or resuming, you use the setTimeout(function,timeout) function.

    This has though some impact in how you break up your code into function. I assume you want to do something like that - in pseudo code:

    myfunction() - definition:
    - do thing A();
    - wait(1 minute);
    - do thing B();
    
    ...
    
    myfunction()  - invocation
    

    The myfunction() construct has to be broken up into two pieces(*):

    var myfunctionPartA = function() {
      code that does the A()-thing
      setTimeout(function(){
          myfunctionPartB();
        },60000); // after 60 secs invoke ...partB
    };
    
    var myfunctionPartB = function() {
      code that does the B()-thing
    };
    
    myfunctionPartA(); // invocation
    

    In case you have first to do something A(), then do something else and repeat it every minute until a condition is met, and then - finally - something B(), the construction looks like this:

    var myfunction = function() {
      code do the A()-thing;
      myfunctionRepeatPart();  
    };
    
    var myfunctionRepeatPart = function() {
      code that does the repeat thing;
      if (conditionNotMetYet) {
          setTimeout(function(){
            myfunctionRepeatPart();
          },60000); // after 60 secs invoke repeat-thing again
      } else {
        code that does the B()-thing
      }
    };
    
    myfunction(); // invocation
    
About

Avatar for allObjects @allObjects started