我在 React Native 应用程序中使用 Realm.io 数据库。我有一个简单的写命令:
Realm.write(() => {
Realm.create('Dog', { name: 'Bob'}, true);
});
//Few lines below, make a query for the Bob the dog.
如果由于某种原因写操作需要超过几毫秒,我如何确保当我查询 Bob the dog 时,我将获得更新的对象?
有没有办法让写操作返回 promise 或类似的东西,所以我可以确保只有在写操作成功后才执行代码?
最佳答案
Realm 是同步的。 All callbacks handed to #write are blocking ,但这没什么大不了的,因为它是为 React Native 优化的。仍然,the docs say
Write transactions incur non-negligible overhead - you should architect your code to minimize the number of write transactions.
关于react-native - React Native Realm 数据库 : How to return a promise from a write command?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39338529/