react-native icon indicating copy to clipboard operation
react-native copied to clipboard

setInterval() using adjusted duration indefinitely

Open ali-rantakari opened this issue 4 years ago • 3 comments

Description

The timer API implementations want to adjust the initial delay to take into account the time it took for the registration call to arrive from JS to the native side.

It seems that on Android, in the case of a repeating timer (setInterval), the adjusted duration is used for all repeated ticks instead of just the initial one:

https://github.com/facebook/react-native/blob/657c48c21de496734716ed33c9e55d8baae3494f/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java#L345

The effect of this is that if during the time when setInterval is invoked, something is happening in the process that's slowing down the calls to the native timer implementation, the required delay adjustment will be significant, and will cause all subsequent interval ticks to fire too quickly.

The change seems to have been introduced in f054928124a2308b2bd450acf8bb754a92ccb16a.

Version

0.65.1

Output of react-native info

System: OS: Windows 10 10.0.19042 CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz Memory: 4.83 GB / 15.76 GB Binaries: Node: 14.18.0 - C:\Program Files\nodejs\node.EXE Yarn: Not Found npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Version 2020.3.0.0 AI-203.7717.56.2031.7678000 Visual Studio: Not Found Languages: Java: 11.0.12 - C:\Program Files\Amazon Corretto\jdk11.0.12_7\bin\javac.EXE npmPackages: @react-native-community/cli: 6.0.0 => 6.0.0 react: 17.0.2 => 17.0.2 react-native: 0.65.1 => 0.65.1 react-native-windows: 0.65.1 => 0.65.1 npmGlobalPackages: react-native: Not Found

Steps to reproduce

Invoke setInterval() with a delay of 1000 while the process is very busy doing other things.

Expected: The given interval function to be invoked every 1000ms. Actual: The given interval function is invoked much more quickly.

Snack, code example, screenshot, or link to a repository

No response

ali-rantakari avatar Nov 10 '21 07:11 ali-rantakari

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 10 '22 02:05 github-actions[bot]

This issue is still valid. (Commenting to keep the issue from being closed as stale.)

ali-rantakari avatar May 15 '22 05:05 ali-rantakari

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Apr 03 '24 05:04 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Apr 10 '24 05:04 github-actions[bot]