question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to run the timer in smaller intervals (500ms)

See original GitHub issue

Hi,

I had a use case where I needed to run a timer in 1.5 seconds and saw that it was running every second because of the setInterval that is set to run each 1000ms.

I was wondering whether there is a reason not to support that? I could work on adding that myself.

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rafmsoucommented, Sep 4, 2020

Hi @amrlabib , no, its not that. I’ll try to give you a concrete example:

If you try to run a task in 1.5 seconds from now, it will actually run in 1 second from now. If you try to run a task in 500 milliseconds it will run in 1 second.

That’s because the min interval in which tasks are checked is fixed in 1000ms (1 sec). So, any task that needs to run in a not rounded number of seconds will not get executed in the correct moment.

If you accept a custom parameter for the min interval, it will work, however there’s more things that might need to change because some places assumes the number of seconds is round (or it gets rounded/floored).

I would say that the goal here would be to make it possible to run timers in intervals less than a second (100ms, 300ms, 500ms) accurately.

Does that makes sense?

0reactions
yoiangcommented, Sep 20, 2021

Haha I have a similar request, except that I’d love to be able to get sub-seconds (milliseconds) from useStopwatch! Maybe by specifying an update interval…?

Happy to make a PR, just checking if you already know a quick change or any gotchas before I try my hand!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a more accurate way to create a Javascript timer than ...
In my experience, the timer is horribly inaccurate in a lot of situations. By inaccurate, I mean the actual delay time seems to...
Read more >
How do I use the timers? - Intervals Help Documentation
Each user can start a general timer or a task timer based on their preference and what they are working on. Administrator level...
Read more >
Lesson 8: Timers - Simply Embedded
In this scenario, the timer runs until one of these two events happen at which ... We could then set the output mode...
Read more >
555 Timer Tutorial - The Monostable Multivibrator
Electronics Tutorial about the 555 Timer and how the 555 can be used as a Monostable or Bistable Timer to Generate Delay and...
Read more >
Timer.Interval Property (System.Timers) | Microsoft Learn
Gets or sets the interval, expressed in milliseconds, at which to raise the Elapsed event. ... AutoReset = true; // Start the timer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found