Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.04 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. javascript - multiple settimeouts in loop
  2. function fnIterateGeocode(addressVariations) {
  3.  
  4.     // read a file & do some stuff  
  5.  
  6.     // check for delay
  7.     fnDelay();
  8.  
  9.    // if not end of file then Iterate
  10.    if (nextRecord.EOF != 'Y') {
  11.         setTimeout(function(){                      
  12.             fnIterateGeocode(addressVariations);                        
  13.         }
  14.         , 5000);
  15.     }
  16.  
  17.  
  18.     // if mode = STOP, then delay for 5 seconds and check again    
  19.  
  20.     function fnDelay(){
  21.         if(mode == 'STOP'){
  22.                 setTimeout(function(){                                                      
  23.                 }
  24.                 , 5000);
  25.                 fnDelay();
  26.         }
  27.         return;
  28.     }          
  29.  
  30.     return;
  31. }
  32.        
  33. function fnDelay(){
  34.     if(mode == 'STOP'){
  35.             setTimeout(function(){
  36.                 // It should be here
  37.             }
  38.             , 5000);
  39.             fnDelay(); // Not here
  40.     }
  41.     return;
  42. }
  43.        
  44. function fnDelay(){
  45.     if(mode != 'STOP'){ fnIterateGeocode(); }
  46.     else { setTimeout(fnDelay,5000);
  47. }