1. In Visual Studio add the `RNThread.sln` in `node_modules/react-native-thread/windows/RNThread.sln` folder to their solution, reference from their app.
1. In Visual Studio add the `RNThread.sln` in `node_modules/react-native-thread/windows/RNThread.sln` folder to their solution, reference from their app.
...
@@ -44,10 +83,50 @@
...
@@ -44,10 +83,50 @@
## Usage
## Usage
In your application code (react components, etc.):
```javascript
import{Thread}from'react-native-threads';
// start a new react native JS process
constthread=newThread('path/to/thread.js');
// send a message, strings only
thread.postMessage('hello');
// listen for messages
thread.onMessage=(message)=>console.log(message);
// stop the JS process
thread.terminate();
```
In your thread code (dedicated file such as `thread.js`):
```javascript
```javascript
importRNThreadfrom'react-native-thread';
import{self}from'react-native-threads';
// TODO: What to do with the module?
// listen for messages
RNThread;
self.onmessage=(message)=>{
}
// send a message, strings only
self.postMessage('hello');
```
```
Check out the examples directory in this repo for demos of using `react-native-thread`
in a functioning app!
### Thread Lifecycle
- Threads are paused when the app enters in the background
- Threads are resumed once the app is running in the foreground
- During development, when you reload the main JS bundle (shake device -> `Reload`) the threads are killed
### Debugging
Instantiating Threads creates multiple react native JS processes and can make debugging
remotely behave unpredictably. I recommend using a third party debugging tool like
[Reactotron](https://github.com/infinitered/reactotron) to aid with this. Each process,
including your main application as well as your thread code can connect to Reactotron