Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

后台脚本, 在上一次还没运行结束的时候, 下个运行时会直接中断上次的吗? #251

Closed
hhuimie opened this issue Jan 8, 2024 · 1 comment

Comments

@hhuimie
Copy link

hhuimie commented Jan 8, 2024

比如一个脚本, 后台每分钟运行一次, 第一次是2024-1-8 14:11:00运行, 运行时间可能远超1分钟, 这时候如果到2024-1-8 14:12:00, 会直接终止目前2024-1-8 14:11:00还在运行的脚本, 然后重新开始吗?
请问如何避免这种情况呢?
浏览器: Edge
ScriptCat版本: 0.16.0
示例代码:

// ==UserScript==
// @name         New Userscript
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @description  try to take over the world!
// @author       You
// @crontab      * * * * *
// ==/UserScript==

return new Promise((resolve, reject) => {
    // Your code here...
    let count = 0;
    setInterval(function(){
        ++count;
        if(count>65){
            resolve();
        }else{
            console.log(count);
        }
    },1000)
    
});

image

@CodFrm
Copy link
Member

CodFrm commented Jan 8, 2024

会中断的

如果有这种脚本,我觉得是脚本的设计不合理,应该加入超时机制,或者延长间隔时间,或者使用GM_value来存储数据,下次调用使用value数据

@CodFrm CodFrm closed this as completed Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants