react-native - React Native Realm 数据库 : How to return a promise from a write command?

标签 react-native promise realm

我在 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/

相关文章:

react-native - 更新 Flatlist 数据后的 ScrollToEnd

android - 使用 React Native for Android 从 bundle 加载 JS/CSS

javascript - React Native-如何将状态从组件传递到其父组件

node.js - Nodejs中Promise的实现在哪里?

ios - Swift:如何迁移自定义 Realm

javascript - React 检测到 Navigation 调用的 Hooks 的顺序发生了变化

javascript - Q :then callback? 中的静默异常

javascript - 如何让 Promise 等待循环中的所有请求都完成?

swift - 我可以在不知道对象是什么类型的情况下从数据库中获取对象吗?

swift - 由于 nil 可选值,无法在详细信息 View 中设置 Realm 数据库对象的属性