Add setInterval and tests #104
Merged
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.
This PR adds a
setIntervalimplementation. This is largely copied over from the related change in Babylon Native: BabylonJS/BabylonNative@b2d5b2e#diff-23ceed54341331df9f4df6a9141772cd3613446bef20c7d96c62f5bebdbcf426However, 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 callclearTimeoutbefore the dispatched callback is executed. This would result in the callback being called even after a call toclearTimeout. This became more obvious withsetInterval, 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 toclearTimeout, 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.