https://github.com/austinksmith/react-native-workerbee
Worker Thread Support For ReactNative Using STD::Thread
https://github.com/austinksmith/react-native-workerbee
Last synced: 4 months ago
JSON representation
Worker Thread Support For ReactNative Using STD::Thread
- Host: GitHub
- URL: https://github.com/austinksmith/react-native-workerbee
- Owner: austinksmith
- License: artistic-2.0
- Created: 2024-10-12T22:51:03.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-26T14:43:43.000Z (about 1 year ago)
- Last Synced: 2025-08-29T06:18:00.747Z (5 months ago)
- Language: C++
- Size: 202 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-workerbee
A Web Worker-like implementation for React Native using JSI.
**Author**: Austin K. Smith

[](https://www.npmjs.com/package/react-native-workerbee)
[](https://www.npmjs.com/package/react-native-workerbee)
## Installation
```sh
npm install react-native-workerbee
# or
yarn add react-native-workerbee
```
### Android Setup
1. Open up `android/app/src/main/java/[...]/MainApplication.java`
- Add `import com.austinksmith.reactnativeworkerbee.WorkerBeePackage;` to the imports at the top of the file
- Add `packages.add(new WorkerBeePackage());` in the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```gradle
include ':react-native-workerbee'
project(':react-native-workerbee').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-workerbee/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```gradle
implementation project(':react-native-workerbee')
```
## Usage
```javascript
import WorkerBee from 'react-native-workerbee';
// Create a new worker
const worker = new WorkerBee('path/to/your/worker/script.js');
// Post a message to the worker
worker.postMessage({ type: 'START', payload: { /* ... */ } });
// Terminate the worker
worker.terminate();
```
## API
### `constructor(scriptURL: string)`
Creates a new WorkerBee instance.
- `scriptURL`: The path to your worker script file.
### `postMessage(message: any)`
Sends a message to the worker.
- `message`: The message to send to the worker. This will be serialized to JSON.
### `terminate()`
Terminates the worker.
## Platform Support
Currently, this module only supports Android. iOS support is planned for future releases.
## License
Artistic License 2.0