Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got the project running, but postmessage never reaches my worker.thread.js #90

Open
Genhain opened this issue Nov 5, 2019 · 4 comments

Comments

@Genhain
Copy link

Genhain commented Nov 5, 2019

I had to manually install as automatic would never run. however i eventually got it running and have placed breakpoints in XCode and confirm that postmessage is being called but the said message never reaches my worker.thread.js

I also had to specify an absolute path for it to work like so

componentDidMount() {
    this.fetchPartiesAndPopulatePartyList()
    this.workerThread = new Thread('src/app/components/party/worker.thread.js')
    this.workerThread.onmessage = this.handleMessage;

    setTimeout(() => {
      this.workerThread.postMessage('Hello')
    }, 1000);
    
  }

otherwise it would say the file did not exist.

and here is my worker thread.js

import { self } from 'react-native-threads';
import Reactotron from 'reactotron-react-native'

console.tron = { log: Function.prototype };

if (__DEV__) {
  Reactotron
    .configure()
    .useReactNative()
    .connect();

  console.tron = Reactotron;
}

let count = 0;

self.onmessage = message => {
  console.tron.log(`THREAD: got message ${message}`);

  count++;

  self.postMessage(`Message #${count} from worker thread!`);
}
@vishalnarkhede
Copy link

vishalnarkhede commented Nov 30, 2019

I have the same issue!! Did you manage to find a solution @Genhain?

@mauriciopf
Copy link

@vishalnarkhede @Genhain did you find the solution for this issue?

@mauriciopf
Copy link

@vishalnarkhede @Genhain
When the callback gets called from listeningDeviceEventEmitter.addListener('ThreadMessage', (message) => {
Doing a console of self it seems that onmessage is null thats why Im assuming self.onmessage is never called
{ onmessage: null, postMessage: [Function: postMessage] }

Can someone tell if this is true?

@liran
Copy link

liran commented Sep 12, 2020

In my case:

// main
// start a new react native JS process
const thread = new Thread('thread.js');
// send a message, strings only
thread.postMessage('run');


// thread
// listen for messages
self.onmessage = (message) => {
  console.log(message);
};

However, no message is received in the Thread.js.
My react-native version: 0.63.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants