Giter Site home page Giter Site logo

Comments (5)

rafmsou avatar rafmsou commented on May 28, 2024 1

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?

from react-timer-hook.

amrlabib avatar amrlabib commented on May 28, 2024

Hi @rafmsou thank you for the issue, trying to understand your use case what do you mean by run a timer in 1.5 seconds ? you want to change the default interval from 1000ms (1s) to be 1500 (1.5s) ?

we can pass a custom param to change the default interval but just to confirm, this means that if the custom interval is 1.5s a 1 minute timer will run for (1.5s * 60) = 90s is this what you are trying to achieve ?

from react-timer-hook.

vrgimael avatar vrgimael commented on May 28, 2024

Could we get milliseconds from the hook with minimal modification? That would solve the problem.

A "throttle" prop would be awesome though

from react-timer-hook.

amrlabib avatar amrlabib commented on May 28, 2024

Sorry for the late response, i updated the code of useTimer to handle milliseconds

Example: 1

if expiryTimeStamp will result in a 3.4 seconds [3400 ms] timer, it will behave as mentioned below:

interval values
now 00:00:04
after 400 ms 00:00:03
after 1000 ms 00:00:02
after 1000 ms 00:00:01
after 1000 ms 00:00:00

Example: 2

if expiryTimeStamp will result in a 0.6 seconds [600 ms] timer, it will behave as mentioned below:

interval values
now 00:00:01
after 600 ms 00:00:00

This is handled in v2.0.5, let me know if this is working well, and thank you again for reporting the issue

from react-timer-hook.

yoiang avatar yoiang commented on May 28, 2024

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!

from react-timer-hook.

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.