最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - What to run some functions in the background in React Native (To Avoid blocking the main thread) - Stack Overflow

programmeradmin4浏览0评论

In my react-native app, I need to process 12sets of data 20 times every second. It has resulted the application to work slow on older mobile phones. I can't understand how to run this function separately on the background.

  1. I have already tried few libraries like react-native-threads or react-native-worklets-core. The first is pretty old and the second one doesnt work (or atleast their documents is old).
  2. I researched a bit and it seems like I can also use Native Models or use WASM.

I was wondering is there a better and more efficient way to do this that I don't know about?

In my react-native app, I need to process 12sets of data 20 times every second. It has resulted the application to work slow on older mobile phones. I can't understand how to run this function separately on the background.

  1. I have already tried few libraries like react-native-threads or react-native-worklets-core. The first is pretty old and the second one doesnt work (or atleast their documents is old).
  2. I researched a bit and it seems like I can also use Native Models or use WASM.

I was wondering is there a better and more efficient way to do this that I don't know about?

Share Improve this question asked Mar 10 at 15:36 nawzneennawzneen 1411 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Perhaps you could consider wrapping your function inside setTimeout as it uses the browser's Web API to handle the delay externally, allowing JavaScript to continue running

setTimeout(()=>{
  // function
})

https://medium/@ashishkumarjena1437/understanding-how-settimeout-works-in-javascripts-single-threaded-environment-dd5889ea1599#:~:text=JavaScript%20is%20single%2Dthreaded%2C%20meaning,moves%20to%20the%20callback%20queue.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论