简体   繁体   English

如何在特定时间间隔内调用函数

[英]How to call function in certain time interval

I need to run a certain API function, in a certain time period once the access token is granted, and check the status and inform the user if there any changes. 一旦授予访问令牌,我需要在特定时间段内运行某个API函数,并检查状态并通知用户是否有任何更改。

So far i did it by clicking a button on popup window of the firefox addon and calling the functions background js files, so i can receive the info from the API and notify the user. 到目前为止,我是通过在firefox插件的弹出窗口上单击一个按钮并调用函数background js文件来做到这一点的,因此我可以从API接收信息并通知用户。 But i need to automate this process in background js files. 但是我需要在后台js文件中自动执行此过程。

Are there any firefox inbuild JS API or any other way to achieve this auto API request calling from addon background files? 是否有任何firefox内置JS API或任何其他方式来实现从插件后台文件调用此自动API请求?

Yes, there is, the setInterval() function. 是的,有setInterval()函数。

let inter = setInterval(() => {
    console.log('HI!');
}, 1000);

To stop the timer, just call: clearInterval(inter); 要停止计时器,只需调用: clearInterval(inter);

More info about setInterval() here . 有关setInterval()更多信息,请setInterval() 此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AngularJS:如何在一定时间间隔后调用函数? - AngularJS: how can I call a function after certain time interval? 时间间隔后如何重复调用函数 - How to call function repeatedly after interval of time 具有时间间隔的Java中的函数调用助手函数 - Call A Helper Function to a function in Javascript with Time Interval 如何使QUnit等待一定的时间间隔? - How to make QUnit wait for certain interval of time? 如何在特定时间间隔内像PHP中的setTimeout()函数那样在PHP中隐式执行函数? - How to keep on execute a function implicitly in PHP at certain time interval like setTimeout() function in JavaScript? 如何在一定间隔内重新执行功能? - How to re-execute a function in a certain interval? 仅在一天的特定时间以设置的间隔运行功能 - Run function at set interval only at certain time of the day 在指定的时间间隔后第一次调用函数 - Call function first time after specified time interval 如何使用钩子以固定的时间间隔触发功能,并且在满足某些条件时我想清除时间间隔? - How to trigger a function at regular intervals of time using hooks and when certain criteria is met I want to clear the time interval? 如何结束用于调用 function 的间隔,该间隔使用 Howler.js 更新时间 - How to end interval used to call function which updates time with Howler.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM