RN: Realm JS 'write' method is handled a/synchronously?
See original GitHub issueGoals
Tried to get data immediately from Realm DB after writing into DB using Redux via dispatching Action
Expected Results
Data on the screen update from Realm DB immediately after insert / update / delete
Actual Results
When I ‘read’ Realm DB and then handle previously read information it goes synchronously and next code is runned step by step. According to documentation ‘write’ method takes much time so it must be called synchronously. But when I put ‘write’ some data and run next some code (redux dispatch to update Store Data) it’s not up to date. Only Notifications via ‘addListener’ works, but those updates are often slowly even in NOT Debugger Mode. So if ‘write’ is handle
Steps to Reproduce
- Call Realm ‘write’ method
- Call Redux Action to update Screen Data from DB via Dispatching Reducers
Code Sample
...
const {updateScreenData} = this.props;
...
realm.write(()=>{
...some update/insert...
});
updateScreenData(); // call Redux Action
Version of Realm and Tooling
- Realm JS SDK Version: 1.10.3
- React Native: 0.47
- Client OS & Version: iOS 11.0 / iOS 10.3
- Which debugger for React Native: Chrome Debugger / none
Is Realm JS ‘write’ method a/synchronously? 'Cause I can’t understand those things above
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
reactjs - Realm js run query async - Stack Overflow
Realm query is synchronous, there is no way to make it async. Look like you are using realm with React Native, if this...
Read more >How to use Realm Local DB in React Native? - Medium
In this post, I will walk you through the process of setting up a local Realm DB in your React Native application.
Read more >Realm React Native and Node.js - MongoDB
Asynchronously submits install information to Realm. Why are we doing this? In short, because it helps us build a better product for you....
Read more >realm | Yarn - Package Manager
This project hosts the JavaScript versions of Realm. Currently we support React Native (JSC & Hermes on iOS & Android), Node.js and Electron...
Read more >React Native with async, await, try, catch, fetch for displaying ...
Asynchronous functions are so common that JS provides us a technique to handle them as if they were synchronous. D) Add async &...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Realm.writeexecutes synchronously, so it seems entirely pointless to wrap it in a promise rather than just executing code after it returns. It may even be harmful, since you’re resolving the promise within the write transaction, while you almost certainly want subsequent code to run after the transaction has been committed.wrap this in a Promise:
And have fun:
Even more fun with async/await: