react-native-threads icon indicating copy to clipboard operation
react-native-threads copied to clipboard

onmessage is null

Open mauriciopf opened this issue 5 years ago • 2 comments

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?

mauriciopf avatar Feb 25 '20 18:02 mauriciopf

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 avatar May 28 '20 11:05 roaringUnicorn

Ok, RTFM...

It is not

self.onmessage(callbackFn)

but

self.onmessage = callbackFn

roaringUnicorn avatar May 28 '20 13:05 roaringUnicorn