Warm tip: This article is reproduced from serverfault.com, please click

Combine two javascript Functions in one

发布于 2020-12-01 11:32:13

I'm a beginner with Angular and Javascript, I'm trying to refresh a dashboard. so I use the first one to do the refresh and the second one to stop the refresh. I want to combine these two functions to refresh and stop after a period of time.

    let refreshInterval;
    function refreshDataSource(){
      console.log("going to refresh ..")
      refreshInterval= setInterval(() => {
        console.log("refreshing ...");
        viz.refreshDataAsync();
      },3000);
    }

    function stopdata(){
      console.log("stop refresh ...");
      clearInterval(refreshInterval);
    }
Questioner
isawid
Viewed
0
Avadh Vashisth 2020-12-01 19:45:55

Inside the function refreshDataAsync() you can call stopdata() after you are done with your operations.

or you can also await the function refreshDataAsync() and then call stopdata() inside refreshDataSource().