Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multi threading in 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).

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.

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.

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?

like image 729
cancan Avatar asked Sep 09 '17 11:09

cancan


People also ask

How many threads work in React Native?

The renderer uses three different threads: UI thread (often called main): The only thread that can manipulate host views. JavaScript thread: This is where React's render phase is executed. Background thread: Thread dedicated to layout.

What is meant by multi threading?

Multithreading is the ability of a program or an operating system to enable more than one user at a time without requiring multiple copies of the program running on the computer. Multithreading can also handle multiple requests from the same user.

What is multi threading explain with example?

What is MultiThreading? Multithreading enables us to run multiple threads concurrently. For example in a web browser, we can have one thread which handles the user interface, and in parallel we can have another thread which fetches the data to be displayed. So multithreading improves the responsiveness of a system.

Why we should use multi thread?

Multithreading allows the execution of multiple parts of a program at the same time. These parts are known as threads and are lightweight processes available within the process. So multithreading leads to maximum utilization of the CPU by multitasking.


1 Answers

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.

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

like image 71
Takuya Matsuyama Avatar answered Sep 23 '22 11:09

Takuya Matsuyama