Enabling setInterval or react-idle-timer to Run in Computer Sleep Mode

25 views Asked by At

I'm currently working on a project where I need to execute periodic tasks in a React application, ideally every 28 minutes. However, I've encountered an obstacle with setInterval as it seems to pause when the user's computer enters sleep mode. This limitation prevents the execution of scheduled tasks during inactive periods.

I'm seeking guidance on alternative approaches or techniques that would allow me to run scheduled tasks even when the user's computer is in sleep mode.

Any insights, suggestions, or examples on how to address this issue would be greatly appreciated. Thank you in advance for your assistance!

  useEffect(() => {
    const interval = setInterval(() => {
      refreshAccessToken();
    }, 28 * 60 * 1000);

    return () => {
      clearInterval(interval);
    };
  }, []);

or with react-idle-timer getTotalElapsedTime method doesnt work on sleep mode

0

There are 0 answers