反应原生的多线程 [英] multi threading in react-native

查看:92
本文介绍了反应原生的多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个React-Native应用程序,我想使用并行编程(我想使用平板电脑的所有内核)。

I have a React-Native application and I want to use parallel programming (I want to use all of the cores of the tablet).

我试过 paralleljs hamsters.js 库但它们没用。一个人不支持RN,另一个人目前在Blob方面存在一些问题。

I tried paralleljs and hamsters.js libraries but they were not useful. One doesn't support RN and the other has some issues with Blobs at the moment.

所以,我决定使用网络工作者。在对它进行了一些搜索之后(来自MDN等),我意识到我可能只使用Web worker而不是所有这些库。但是我无法100%肯定它。还有其他为RN设计的库,比如react-native-workers,但都有很多问题。

So, I decided to use web-workers. After doing some search on it (from MDN etc), I realized that I might use web workers alone instead of all these libraries. However I can't be 100% sure about it. There are other libraries designed for RN, like react-native-workers, but all has lots of issues.

我的问题是如何使用纯JS代码来使用多个在React-Native应用程序中进行线程化和/或并行编程?或者它不可能吗?

My question is how to use pure JS code to make use multi-threading and/or parallel programming in a React-Native application? Or is it not possible yet?

推荐答案

您可以使用将在后台线程中运行JS的WebView。
因为在webview中,它是Webkit的另一个实例,因此在其中运行的JS根本不会阻止应用程序UI。

You can use WebView which will run JS in background thread. Because inside webview, it is another instance of Webkit, so JS running in it won’t block the app UI at all.

阅读此博文了解更多信息细节: https://medium.com/@inkdrop/a-simple-way-to-run-js-in-background-thread-on-react-native-8fff345576da

Read this blogpost for more detail: https://medium.com/@inkdrop/a-simple-way-to-run-js-in-background-thread-on-react-native-8fff345576da

这篇关于反应原生的多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆