gpt4 book ai didi

javascript - 在 Meteor.js 中, stub 的数据库写入是否总是在 stub 完成后立即完成?

转载 作者:行者123 更新时间:2023-12-03 08:09:23 25 4
gpt4 key购买 nike

当调用 Meteor 中客户端和服务器端的方法时,会出现模拟的 stub运行。我假设 stub 将在调用该方法的同一行上同步运行,并将向模拟的 minimongo 数据库发出写入。

现在我的问题是:调用方法后,我可以依赖 stub 的数据库写入在客户端 minimongo 数据库中立即可用吗?更准确地说,“立即”我的意思是:

  1. 在方法调用后,客户端数据库是否会在下一个代码行更新(通过 stub )?
  2. 如果我在延迟函数运行时在下一个代码行上发出 Meteor.defer ,客户端数据库是否会更新(通过 stub )?

最佳答案

对 minimongo 的写入是同步的,因此假设您的方法 stub 仅包含同步操作,那么答案是"is"。让我们举个例子:

Meteor.methods({
gotime: function() {
Posts.insert({text: 'hello'});
}
});

现在,在客户端的其他地方:

// call the stub method (note there is no callback passed)
Meteor.call('gotime');
// the new document will be available here
post = Posts.findOne();

关于javascript - 在 Meteor.js 中, stub 的数据库写入是否总是在 stub 完成后立即完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34210495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com