{"id":28789946,"url":"https://github.com/colyseus/timer","last_synced_at":"2025-09-13T15:41:45.470Z","repository":{"id":57113031,"uuid":"47463656","full_name":"colyseus/timer","owner":"colyseus","description":"Timing Events tied to @colyseus/clock","archived":false,"fork":false,"pushed_at":"2025-02-21T13:09:47.000Z","size":155,"stargazers_count":26,"open_issues_count":7,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-14T01:15:53.901Z","etag":null,"topics":["clock","setinterval","settimeout"],"latest_commit_sha":null,"homepage":"https://github.com/colyseus/clock","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/colyseus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-05T16:39:02.000Z","updated_at":"2025-02-21T13:09:51.000Z","dependencies_parsed_at":"2024-10-26T19:34:16.575Z","dependency_job_id":"721f2a83-4733-4d5b-b930-226e2cf29d3e","html_url":"https://github.com/colyseus/timer","commit_stats":{"total_commits":32,"total_committers":5,"mean_commits":6.4,"dds":0.1875,"last_synced_commit":"bb39a7bd83b04fbf67718e554913616cfbf96930"},"previous_names":["gamestdio/clock-timer.js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/colyseus/timer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colyseus%2Ftimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colyseus%2Ftimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colyseus%2Ftimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colyseus%2Ftimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/colyseus","download_url":"https://codeload.github.com/colyseus/timer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colyseus%2Ftimer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260449989,"owners_count":23010986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clock","setinterval","settimeout"],"created_at":"2025-06-17T22:31:13.891Z","updated_at":"2025-09-13T15:41:45.462Z","avatar_url":"https://github.com/colyseus.png","language":"TypeScript","readme":"# @colyseus/timer\n\nTiming Events tied to [colyseus/clock](https://github.com/colyseus/clock).\n\n`ClockTimer` is a subclass of `Clock`, which adds methods to handle timeout and\nintervals relying on `Clock`'s ticks.\n\n## Why?\n\nOnce built-in `setTimeout` and `setInterval` relies on CPU load, functions may\ndelay an unexpected amount of time to execute. Having it tied to a clock's time\nis guaranteed to execute in a precise way.\n\nTherefore there is ideally one single CPU clock for all the timers and then they are executed in sequence.\n\nSee a quote from [W3C Timers Specification](http://www.w3.org/TR/2011/WD-html5-20110525/timers.html):\n\n\u003e This API does not guarantee that timers will fire exactly on schedule. Delays\n\u003e due to CPU load, other tasks, etc, are to be expected.\n\nIt 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.\n\nIn classic timer if we have a `setInterval` of `0`ms it will fill the event loop timer queue with callbacks (like A LOT) and if we have another of `1000`ms interval it will be executed only after many of the `0`ms 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 `1000`ms callback will be executed in time.\n\nYou can also call `.tick()` manually to check all the timers at once on a specific important time.\n\nOther 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.\n\n## API\n\n**Clock**\n\n- `setInterval(handler, time, ...args)` -\u003e `Delayed`\n- `setTimeout(handler, time, ...args)` -\u003e `Delayed`\n- `duration(ms: number)` -\u003e `Promise\u003cvoid\u003e` - Convenience method to wait for a duration in async functions or promises. See associated JSdoc for more details.\n- `clear()` - clear all intervals and timeouts, and throw any promise created with `duration`.\n\n**Delayed**\n\n- `clear()` -\u003e `void` - Clear timeout/interval\n- `reset()` -\u003e `void` - Reset elapsed time\n- `active` -\u003e `Boolean` - Is it still active?\n- `pause()` -\u003e `void` - Pause the execution\n- `resume()` -\u003e `void` - Continue the execution\n- `paused` -\u003e `Boolean` - Is is paused?\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolyseus%2Ftimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolyseus%2Ftimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolyseus%2Ftimer/lists"}