Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Realm database: How to return a promise from a write command?

I am using Realm.io database in a React Native app. I have a simple write command:

    Realm.write(() => {
        Realm.create('Dog', { name: 'Bob'}, true);
    });  

    //Few lines below, make a query for the Bob the dog.

If the write operation for some reason takes more then couple of milliseconds, how can I make sure that when I query for Bob the dog, I will get the updated object?

Is there a way for the write operation to return a promise or something simillar so I can be sure to execute code only after the write operation succeeded?

like image 853
Yaron Levi Avatar asked Sep 05 '16 22:09

Yaron Levi


1 Answers

Realm is synchronous. All callbacks handed to #write are blocking, but that's not such a big deal as it is optimized for React Native. Still, the docs say

Write transactions incur non-negligible overhead - you should architect your code to minimize the number of write transactions.

like image 63
broguinn Avatar answered Oct 19 '22 23:10

broguinn