-
Notifications
You must be signed in to change notification settings - Fork 13
Refactor timer system from child processes to main thread #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor timer system from child processes to main thread #216
Conversation
Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
AlecM33
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along with my other feedback, please remove all code comments you have added. Do not use any code comments in your work unless you think it's absolutely necessary to prevent confusion.
Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
Removed all code comments from GameManager.js and Events.js. Commit: a2f8844 |
AlecM33
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple things that aren't working:
When an instance of the app tries to get the time remaining, and the timer lives on another instance, it never receives it. I think this has something to do with the SOURCE_TIMER event when we want to GET_TIME_REMAINING - it never gets published for all instances to consume.
Second, after the timer has ran, no instances are able to get the time remaining. In this case we should be able to reliably return 0 time remaining.
- GET_TIME_REMAINING now publishes response through Redis for cross-instance communication - SOURCE_TIMER_EVENT handles GET_TIME_REMAINING even when timer is not running locally - Returns 0 time remaining when timer has expired or timerParams is null - Updated test to expect Redis publish instead of direct method call Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
Fixed both issues:
Commit: 4e0f3d5 |
AlecM33
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the timer ends, lets set a property on the timerParams "ended: true", and make sure the timeRemaining is 0.
Then, let's simplify GET_TIME_REMAINING. The flow should go like this:
- We receive the socket event. We pass that to the TIMER_EVENT handler. First, just check if the timer is ended. If it is, just send the relevant timer params to the socket.
- If it isn't ended, check if this instance is home to the timer. If it is, send the relevant timer params to the socket.
- If it isn't home to the timer, publish the SOURCE_TIMER event like we're doing now. The SOURCE_TIMER handler should likewise check if the instance is home to the timer. If it is, publish the GET_TIME_REMAINING event, which other instances will receive and handle just like they're doing now - by checking if they have the connected socket and communicating to it if they do.
- Add ended: true flag to timerParams when timer completes - Simplify TIMER_EVENT to check ended flag first, then local timer, then publish SOURCE_TIMER_EVENT - SOURCE_TIMER_EVENT only publishes GET_TIME_REMAINING if it has the timer - Remove GET_TIME_REMAINING from handleTimerCommand helper - Direct socket emission for local timers instead of Redis publish - Updated test to verify socket emission Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
Simplified the GET_TIME_REMAINING flow as requested:
The flow is now much cleaner with direct socket emission for local cases and Redis pub/sub only for cross-instance communication. Commit: d0eeca8 |
- Moved GET_TIME_REMAINING logic from TIMER_EVENT handler into handleTimerCommand function - Simplified TIMER_EVENT to just call handleTimerCommand for all timer operations - Maintains same flow: check ended flag, check local timer, publish SOURCE_TIMER_EVENT if needed - All tests passing Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
- Function is no longer called after refactoring GET_TIME_REMAINING into handleTimerCommand - All timer time remaining logic now handled in Events.js handleTimerCommand switch case - Tests still passing Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
- Added reset of ended flag to false in restartGame function - Ensures restarted games don't have timer marked as already ended - Placed right after timer cleanup for logical grouping Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
Timer System Refactor: Child Process to Main Thread
✅ All Changes Complete:
Summary:
Timer system successfully refactored from child processes to main thread:
Original prompt
This pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.