加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – React Native Realm数据库:如何从write命令返

发布时间:2020-12-15 20:14:02 所属栏目:百科 来源:网络整理
导读:我在React Native应用程序中使用Realm.io数据库.我有一个简单的写命令: Realm.write(() = { Realm.create('Dog',{ name: 'Bob'},true); }); //Few lines below,make a query for the Bob the dog. 如果由于某种原因写入操作花费的时间超过几毫秒,我怎样才能
我在React Native应用程序中使用Realm.io数据库.我有一个简单的写命令:

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

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

如果由于某种原因写入操作花费的时间超过几毫秒,我怎样才能确保当我查询Bob的狗时,我会得到更新的对象?

有没有办法让write操作返回一个promise或者simillar,所以我可以确保只在写操作成功后执行代码?

解决方法

领域是同步的. 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读