npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gamestdio/timer

v1.4.1

Published

Timing Events tied to @gamestdio/clock

Downloads

18,370

Readme

@gamestdio/timer

Timing Events tied to colyseus/clock.

ClockTimer is a subclass of Clock, which adds methods to handle timeout and intervals relying on Clock's ticks.

Why?

Once built-in setTimeout and setInterval relies on CPU load, functions may delay an unexpected amount of time to execute. Having it tied to a clock's time is guaranteed to execute in a precise way.

Therefore there is ideally one single CPU clock for all the timers and then they are executed in sequence.

See a quote from W3C Timers Specification:

This API does not guarantee that timers will fire exactly on schedule. Delays due to CPU load, other tasks, etc, are to be expected.

It does however guarantees an order of « does this timer should execute based on elapsed time since last tick call ? » based on when they were registered.

In classic timer if we have a setInterval of 0ms it will fill the event loop timer queue with callbacks (like A LOT) and if we have another of 1000ms interval it will be executed only after many of the 0ms callbacks are executed. This is not the case with ClockTimer, as it loops through all timers and checks if they should be executed there are more chance that the 1000ms callback will be executed in time.

You can also call .tick() manually to check all the timers at once on a specific important time.

Other cool stuff is that you manage all your timers in one place and therefore you can clear all of them at once. This is useful for example when you want to clear all timers when a game is over. Or when using those is irrelevant.

API

Clock

  • setInterval(handler, time, ...args) -> Delayed
  • setTimeout(handler, time, ...args) -> Delayed
  • duration(ms: number) -> Promise<void> - Convenience method to wait for a duration in async functions or promises. See associated JSdoc for more details.
  • clear() - clear all intervals and timeouts, and throw any promise created with duration.

Delayed

  • clear() -> void - Clear timeout/interval
  • reset() -> void - Reset elapsed time
  • active -> Boolean - Is it still active?
  • pause() -> void - Pause the execution
  • resume() -> void - Continue the execution
  • paused -> Boolean - Is is paused?

License

MIT