[英]Combine two javascript Functions in one
I'm a beginner with Angular and Javascript, I'm trying to refresh a dashboard.我是 Angular 和 Javascript 的初学者,我正在尝试刷新仪表板。 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);
}
Inside the function refreshDataAsync()
you can call stopdata()
after you are done with your operations.在 function
refreshDataAsync()
内部,您可以在完成操作后调用stopdata()
。
or you can also await
the function refreshDataAsync()
and then call stopdata()
inside refreshDataSource()
.或者您也可以
await
function refreshDataAsync()
然后在 refreshDataSource() 中调用stopdata()
refreshDataSource()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.