Skip to content

Conversation

@ryantrem
Copy link
Member

This PR adds a setInterval implementation. This is largely copied over from the related change in Babylon Native: BabylonJS/BabylonNative@b2d5b2e#diff-23ceed54341331df9f4df6a9141772cd3613446bef20c7d96c62f5bebdbcf426

However, with the tests, I did discover a pre-existing timing/threading problem. Specifically, if the callback was scheduled in the JS thread via m_runtime.Dispatch, it is possible that the JS code could call clearTimeout before the dispatched callback is executed. This would result in the callback being called even after a call to clearTimeout. This became more obvious with setInterval, especially with small intervals. I changed the logic so that now the entries are removed from the time map on the timer thread, but the entries in the timer id map are left in place and removed only by calls on the JS thread - either a call to clearTimeout, or in the callback on the JS thread. This way, we know for sure in the callback on the JS thread whether the timer has been cleared.

@ryantrem ryantrem requested review from bghgary and docEdub February 20, 2025 00:37
@ryantrem ryantrem enabled auto-merge (squash) February 20, 2025 01:12
@ryantrem ryantrem merged commit 6c1fba4 into BabylonJS:main Feb 20, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants