1

I have read a bunch of resources online but didn't see any similar use case. I need to send data from native (Android) to JS continuously, with the data being small sized string.

Would this (from RN tutorial)

reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, data)

be the best way to do it? What if we need the message to be sent very frequently? Like every 100ms? Is there any other way to do it with better performance? How frequent can it go?

Thank you!

HeyThere
  • 503
  • 1
  • 5
  • 19
  • 1
    Because JS run on a different thread I don't think there is a better way for sending data than EventEmitter. react-native-sensors use it, so it must be fast enough. – Alexandre Nicolas Mar 04 '19 at 23:47
  • Thank you @Kornflexx for pointing to a good example! Could you please answer this question so I can mark it as selected? – HeyThere Mar 05 '19 at 18:06

1 Answers1

1

In react-native your javascript app is running on a different thread than you native application. I don't thinks there is a better way for sending data between the two threads than EventEmitter.

In the source code of libraries sending data frequently, EventEmitter is always used (example: react-native-sensors).

Alexandre Nicolas
  • 1,851
  • 17
  • 19