Replace 23 raw setTimeout calls in Logo engine with ManagedTimer#5799
Open
Ashutoshx7 wants to merge 1 commit intosugarlabs:masterfrom
Open
Replace 23 raw setTimeout calls in Logo engine with ManagedTimer#5799Ashutoshx7 wants to merge 1 commit intosugarlabs:masterfrom
Ashutoshx7 wants to merge 1 commit intosugarlabs:masterfrom
Conversation
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
57e04bb to
d09c22f
Compare
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
… to prevent zombie timers The Logo execution engine (js/logo.js) used 23 raw setTimeout/setInterval calls for animation dispatch, note scheduling, and completion polling. When users hit Stop, these timers were never cancelled — creating 'zombie timers' that continue firing into the next run, causing ghost animations, doubled audio, and UI glitches. Changes: - Add js/utils/ManagedTimer.js (277 lines): centralized timer lifecycle manager with setTimeout, setGuardedTimeout, setInterval, setGuardedInterval, clearAll, and diagnostic getStats/resetStats methods - Replace all 23 raw setTimeout calls in logo.js with managed/guarded variants that auto-cancel when the stop flag is set - Wire ManagedTimer into RequireJS loader (js/loader.js) as a dependency of Logo - Call timerManager.clearAll() at the top of doStopTurtles() so every pending timer is cancelled the instant the user presses Stop - Harden Publisher.dataToTags with try/catch + Array.isArray guard for malformed project JSON, add module.exports for testability Tests: - 55 new tests for ManagedTimer (js/__tests__/ManagedTimer.test.js, 497 lines) - 4 new tests for Publisher.dataToTags (planet/js/__tests__/Publisher.test.js) - All 112 test suites pass (3167 tests, 0 failures) Fixes zombie timer bug in the core execution engine.
d09c22f to
6f2bcf3
Compare
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
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.
Problem
The Logo execution engine (
js/logo.js) originally fired 23 rawsetTimeoutandsetIntervalcalls for animation dispatch, note scheduling, and UI feedback — but none of these were cancelled when the user pressed Stop. ThedoStopTurtles()method simply setthis.stopTurtle = trueand nothing else. Every pending timer continued firing into the next run, living on as "Zombie Timers," which caused ghost animations, doubled audio, and stuck highlights.Solution
Introduced a new
ManagedTimerutility class (js/utils/ManagedTimer.js) that robustly tracks every timeout and interval, providing a singleclearAll()kill switch.setTimeoutcalls inlogo.jsare now replaced with managed and guarded variants (setGuardedTimeout).doStopTurtles()method now explicitly callsthis._timerManager.clearAll()first — killing every pending timer instantly before they can execute.Architecture Diagrams
BEFORE — Zombie Timers Survive Stop
AFTER — Clean Kill on Stop
Testing Performed
stopcorrectly forceswindow.activity.logo._timerManager.getStats()to reportactive: 0alongside an increasedcancelledmetric.ManagedTimerunit tests passing.Publisher.dataToTagsunit tests passing.