Phase 7: Typed event system + centralized timer manager - #2336
Open
Brainicism wants to merge 7 commits into
Open
Phase 7: Typed event system + centralized timer manager#2336Brainicism wants to merge 7 commits into
Brainicism wants to merge 7 commits into
Conversation
Brainicism
force-pushed
the
refactor/session-phase7-events
branch
from
April 30, 2026 09:08
242be72 to
9400b74
Compare
Brainicism
force-pushed
the
refactor/session-phase1-foundation
branch
from
May 1, 2026 03:37
6da0139 to
c71e0f2
Compare
Brainicism
force-pushed
the
refactor/session-phase7-events
branch
from
May 1, 2026 06:05
42c0759 to
1229cd5
Compare
taahamahdi
requested changes
May 2, 2026
Brainicism
force-pushed
the
refactor/session-phase7-events
branch
3 times, most recently
from
May 2, 2026 19:34
accdc07 to
f499038
Compare
New files:
- src/structures/typed_event_emitter.ts — TypedEventEmitter<T> for
compile-time event name and payload checking
- src/structures/session_events.ts — SessionEvents interface with
roundStart, roundEnd, stateChange, sessionEnd events
- src/structures/timer_manager.ts — TimerManager class with named
set/clear/setInterval/clearInterval/clearAll for leak-proof timer mgmt
Session base class:
- Add events (TypedEventEmitter<SessionEvents>) and timers (TimerManager)
- Replace guessTimeoutFunc field with timers.set('guessTimeout', ...)
- stopGuessTimeout() now uses timers.clear('guessTimeout')
- endSession(): calls timers.clearAll(), emits sessionEnd, removes listeners
GameSession:
- Remove hiddenUpdateTimer field
- startHiddenUpdateTimer() uses timers.setInterval('hiddenUpdate', ...)
- stopHiddenUpdateTimer() uses timers.clearInterval('hiddenUpdate')
Risk: Low — existing timer behavior preserved, just centralized.
Timer cleanup on session end is now guaranteed.
Addresses: RACE-15, RACE-24 (timer/interval leaks on session end)
- TimerManager: remove unused logger import, remove noisy clearAll log - TimerManager: remove restating JSDoc comments - TypedEventEmitter: remove restating removeAllListeners comment - session.ts: remove restating cleanup comment
- Remove roundStart, roundEnd, stateChange from SessionEvents — they were declared but never emitted. Kept sessionEnd which IS emitted. Added comment noting future events will be wired with state machine. - Remove unused SessionState import from session_events.ts - Add comprehensive TimerManager unit tests covering set/clear, intervals, replacement, clearAll, and has()
Introduces a SessionTimerName enum in timer_manager.ts that documents all named timer/interval keys. Replaces raw string literals at callsites in session.ts and game_session.ts with enum values. TimerManager's API stays string-based for flexibility (tests use arbitrary names). Addresses PR review comment from taahamahdi.
Brainicism
force-pushed
the
refactor/session-phase7-events
branch
from
May 2, 2026 19:36
f499038 to
c19b2ec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Session Architecture Redesign — Phase 7 of 8
What
Add type-safe event emitter, centralized timer management, and session lifecycle events.
New Files
typed_event_emitter.ts:TypedEventEmitter<T>wrapping Node's EventEmitter with compile-time event name + payload type checkingsession_events.ts:SessionEventsinterface —roundStart,roundEnd,stateChange,sessionEndtimer_manager.ts:TimerManagerwith namedset()/clear()/setInterval()/clearInterval()/clearAll()— guarantees all timers cleaned on session endChanges to Existing Files
session.ts:events(TypedEventEmitter) andtimers(TimerManager) propertiesguessTimeoutFuncfield withtimers.set('guessTimeout', ...)stopGuessTimeout()→timers.clear('guessTimeout')endSession():timers.clearAll(), emitsessionEnd,events.removeAllListeners()game_session.ts:hiddenUpdateTimerfieldstartHiddenUpdateTimer()→timers.setInterval('hiddenUpdate', ...)stopHiddenUpdateTimer()→timers.clearInterval('hiddenUpdate')Risk: Low
Existing timer behavior is preserved — just centralized under named slots. The
clearAll()call inendSession()is the key safety improvement: no timer can survive past session teardown.Stack Order
Race Conditions Addressed
events.removeAllListeners()on dispose