joltup / react-native-threads

Create new JS processes for CPU intensive work
MIT License
755 stars 141 forks source link

How can I use third party packages in the working.thread.js? #82

Open neller1 opened 5 years ago

neller1 commented 5 years ago

When I import package to working.thread.js code to use it, I get the error "null is not an object (evaluating 'Package_Name')" So, how can I use packages in the threads?

import { self } from 'react-native-threads';
import './config';
import { start, stop } from "react-native-beep-tone";
  var g=false;
    self.onmessage = message => {
        for (let i = 1; i <= 30; i++){
          setTimeout(function(){
            //console.tron.log(`THREAD: got message ${i}`);
                g=!g;
                if (g){
                    start(50);     // Start playing the sound

                }
                else{
                    stop();            // Stop playing the sound

                }

            //self.postMessage(`Message from worker thread!`);
          }, i * 1000);
        }
    }
minicuper commented 5 years ago

Probably this way - https://github.com/joltup/react-native-threads#android-1

Also note that only the official react native modules are available from your threads (vibration, fetch, etc...). To include additional native modules in your threads, pass them into the RNThreadPackage constructor after the mReactNativeHost like this: new RNThreadPackage(mReactNativeHost, new ExampleNativePackage(), new SQLitePackage())

daominhsangvn commented 4 years ago

How can i archive this in ios ?

RiteshJariwala commented 1 year ago

what about if some want to import all the package.json modules to it?