gpt4 book ai didi

javascript - Meteor 中的竞争条件

转载 作者:太空宇宙 更新时间:2023-11-04 16:06:15 24 4
gpt4 key购买 nike

当两个用户更新同一个集合时,Meteor 如何防止竞争条件?我怀疑它与纤维有关。

下面的代码来自待办事项列表教程。如果两个用户同时切换复选框怎么办? meteor 如何防止竞争状况。你能指出我源代码中的正确位置吗?

Template.task.events({                                                                                               
'click .toggle-checked'() {
// Set the checked property to the opposite of its current value
Tasks.update(this._id, {
$set: { checked: ! this.checked },
});
},
'click .delete'() {
Tasks.remove(this._id);
},
});

最佳答案

Meteor 在您的场景中不会执行任何操作,由 MongoDB 来处理。这取决于您使用的存储引擎。

WiredTiger 允许记录级锁定。检查这里:https://docs.mongodb.com/manual/faq/concurrency/#how-granular-are-locks-in-mongodb

For most read and write operations, WiredTiger uses optimistic concurrency control. WiredTiger uses only intent locks at the global, database and collection levels. When the storage engine detects conflicts between two operations, one will incur a write conflict causing MongoDB to transparently retry that operation.

关于javascript - Meteor 中的竞争条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41844806/

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