Skip to content

Conversation

NathanWalker
Copy link
Contributor

What is the current behavior?

The current setInterval function uses a problematic timing calculation that causes drift and incorrect behavior when callbacks take time to execute.
Root Cause: The current implementation tries to align intervals to wall-clock time using:

const startOffset = milliseconds > 0 ? Date.now() % milliseconds : 0;
function nextCallMs() {
    return milliseconds > 0 ? milliseconds - ((Date.now() - startOffset) % milliseconds) : milliseconds;
}

This causes:
Extra callbacks in test_setInterval_callbackNotDelayedByBusyWork because the timing calculation doesn't account for callback execution time properly
Missed callbacks in test_setInterval_callbackSkippedByBusyWork because the busy work throws off the timing alignment

What is the new behavior?

The implementation follows the same pattern as the native C++ implementation in the android runtime, which updates the start time after each execution to prevent drift.

@NathanWalker NathanWalker added this to the 9.0 milestone Aug 28, 2025
Copy link

nx-cloud bot commented Aug 28, 2025

View your CI Pipeline Execution ↗ for commit e07f142

Command Status Duration Result
nx test apps-automated -c=ios ✅ Succeeded 2m 10s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-28 21:39:57 UTC

@NathanWalker NathanWalker force-pushed the fix/android-interval-drift branch from 455bcbd to e07f142 Compare August 28, 2025 21:35
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.

1 participant