joltup / react-native-threads

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

onmessage is null #99

Open mauriciopf opened 4 years ago

mauriciopf commented 4 years ago

When the event emitter is fired, doing a console log of self in the callback DeviceEventEmitter.addListener('ThreadMessage', (message) => { seems that onmessage property is always null { onmessage: null, postMessage: [Function: postMessage] }

So the worker self.onmessage is never getting called

Can someone tell if this is true?

roaringUnicorn commented 4 years ago

I'm having the same problem. Is there any update ?

My thread code look like that:

import { self } from 'react-native-threads'
console.log(self)
self.onmessage([...])

logs:

05-28 12:51:41.308 18302 18597 I ReactNativeJS:  { onmessage: null, postMessage: [Function: postMessage] }
05-28 12:51:41.310 18302 18597 E ReactNativeJS: TypeError: null is not a function (near '...t.self.onmessage...')

"react-native": "^0.61.5", "react-native-threads": "0.0.19",

roaringUnicorn commented 4 years ago

Ok, RTFM...

It is not

self.onmessage(callbackFn)

but

self.onmessage = callbackFn