Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: JavaScript/TypeScript
javascripttimersabort-controllercleanup
Make timeouts abortable via an AbortSignal
Wire timeouts to an AbortSignal so a single controller.abort() can cancel multiple pending timers at once.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const t1 = setTimeout(showFn, 300); |
| 2 | const t2 = setTimeout(hideFn, 300); |
| 3 | // must track and clear each id separately |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | function setAbortableTimeout(fn: () => void, ms: number, signal: AbortSignal) { |
| 2 | const id = setTimeout(fn, ms); |
| 3 | signal.addEventListener('abort', () => clearTimeout(id)); |
| 4 | } |
| 5 | // controller.abort() cancels all of them at once |
Explanation (EN)
Objašnjenje (HR)