Coder Social home page Coder Social logo

Comments (3)

chrisguttandin avatar chrisguttandin commented on June 14, 2024

Hi @sdford,

the implementation of setInterval()/setTimeout() is very similar. It is handled by the worker-timers-worker package in case you want to review it yourself: https://github.com/chrisguttandin/worker-timers-worker/blob/master/src/helpers/timer.ts. setInterval() and setTimeout() both use the native setTimeout() function internally.

I don't know what really happens when a laptop is pretending to sleep. But I would be surprised if it could be woken up by some JavaScript code. If the numbers in your example code are the actual values you used to test the functionality, it could be the case that setInterval() keeps working because the laptop never ever falls asleep when it has to do something every 2 seconds. But if you schedule a timeout to fire in 3 minutes it might fall asleep before the timeout is about to fire.

That's of course just a rough guess. Can you please try to run both functions with the same delay?

from worker-timers.

sdford avatar sdford commented on June 14, 2024

Thanks for the quick response. I believe you're right; at least the explanation sounds believable.

I have increased the timeout to 300000 milliseconds (5 mins), and now observe the same behavior (where setInterval() also does not trigger while the laptop is "asleep", similar to setTimeout).

It seems that setInterval is required (with a small enough time period) to accomplish the results that I would like.

from worker-timers.

chrisguttandin avatar chrisguttandin commented on June 14, 2024

Hi @sdford,

I'm sorry that worker-timers is not working (or at least is not working as expected) for your use case. I haven't tested that, but I could imagine a push notification may be the only thing which is capable of waking up a laptop. That's just a guess and there is a good chance that it might not work as well. But if it does you could "catch" the notification with a ServiceWorker and handle it as you like without showing anything to the user.

I'm closing this issue now as worker-timers can't be modified to support this use case.

from worker-timers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.