2017-04-06 4 views
0

ich für eine elegante Art und Weise bin auf der Suche aus dieser Umfrage zu brechen:Beenden Polling mit Timeout

private pollLinkResult() { 
     (function poll() { 
      setTimeout(() => { 
        //call the service layer to do an ajax call 
       //depending on the result I would like to exit the infinite poll 
      }, 1000); 
     })();  
} 

Irgendwelche Ideen?

+0

In welchem ​​Zustand soll die Abfrage gestoppt werden? – toskv

+0

zum Beispiel jsonContentFromAjax.Completed === wahr – FailedUnitTest

Antwort

1
private pollLinkResult() { 
     (function poll() { 
      let myTimeout = setTimeout(() => { 
        //call the service layer to do an ajax call 
       //depending on the result I would like to exit the infinite poll 
if(yourCondition){ 
clearTimeout(myTimeout); 
} 
      }, 1000); 
     })();  
}