Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

javascript - How to run functions with setIntervals in parallel?

I would like to have these two setInterval functions running in parallel - and looping , however the result I'm getting with the code below is that the first function runs once, and then only the second one keeps getting repeated after it's interval.

 await Promise.all([
        page.evaluate(() => { 
            setInterval(() => {
                (() => {
                    
                    let i = 0;
                    const followInterval = setInterval(() => {
                        if (i >= 2) {
                            clearInterval(followInterval);
                            return;
                        }
                        const buttons = document.querySelectorAll('button');
                        const nextButton = buttons[i];
                        nextButton.click();
                        i += 1;
                    }, 500)
                })();
            }, 7000)
        }),
        
      setInterval(() => {
                page.reload(true)
                }, 11000)
    ]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...