Creating Web Worker in React Native Android app

2020-07-09 02:41发布

I am building a React Native android app. In app I want to download and parse huge amount of data from server. Since JavaScript is a single threaded language I don't want to execute this on same React Native JSC context. Is it possible to create a Web Worker inside React Native JSC context and do extensive background jobs?

I have tried to do the same, but it says function not available.

2条回答
祖国的老花朵
2楼-- · 2020-07-09 03:11

There is a library exactly for that now. Check out https://github.com/devfd/react-native-workers

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-07-09 03:27

AFAIK there is no WebWorker polyfill for React Native. You will probably have to write a Native Bridge Module. If you want to avoid that , check out this post where they use requestAnimationFrame to break heavy tasks. https://corbt.com/posts/2015/12/22/breaking-up-heavy-processing-in-react-native.html

查看更多
登录 后发表回答