0

i wonder if it's possible to write / read from / to realm from different implementations. We have a react native app that uses realm. We would like todo heavy writes to the database via the native side in another thread. So the question is, is that possible with realm? I already read that it's possible to write to it from different threads. But I am not sure what happens if write to it from the native side in swift and listen to database changes in the UI thread of react. We are basically using different threads + different language implementations.

1 Answers1

1

You can write to Realm from multiple threads. But only one writes at a time and the other threads will wait.

Mixing Realm Cocoa (Swift) and Realm JavaScript (React Native) isn't officially supported. You are welcome to dive into https://github.com/realm/realm-js/issues/884. It hasn't been the highest priority to get it to work. Both Realm Cocoa and Realm JavaScripts are open source, and it would be great if the React Native community can help to get it to work and document it.

PS. I work for Realm :-)

geisshirt
  • 2,457
  • 1
  • 17
  • 20
  • Hi. I saw the issue had been closed now that RealmJS is installed through pods. Do you know of an example that shows how you can access a RealmJS realm from Realm Swift? – Eric Wiener Feb 20 '20 at 04:24
  • @EricWiener I am not aware of any examples. I have heard from users that they have it working. – geisshirt Mar 05 '20 at 22:01
  • Thanks. I ended up getting it to work. I’m planning on writing up a post once I get everything working correctly (still having some issues with accessing realm swift from a React Native component that is no longer focused) – Eric Wiener Mar 05 '20 at 22:26
  • 1
    Great to hear. When you write a post about, please let me know. I am certain it will be worth sharing with our users! – geisshirt Mar 09 '20 at 07:47
  • @EricWiener did you write you post about it ? We are trying to multi thread with Realm on ReactNative to insert more than 10 000 data. Thank you – Thomas Lemaitre Jun 21 '21 at 10:38
  • @ThomasLemaitre never got around to writing a post (and now work in a different area of CS for the most part), but this GitHub issue might be of some use https://github.com/realm/realm-js/issues/3588 – Eric Wiener Jun 21 '21 at 15:15