ExtJS 4:重新加载商店时如何防止竞争条件?
当我在第一次加载完成之前第二次加载 TreeStore 时,它会失败。 TreeStore load() 似乎不可重入。
这就是我正在做的让第二个 load() 等待的事情:
loadStore: function(){
var store=this.store;
if (store.isLoading()) this.addListener({
load: function(store,rec,success){
this.loadStore()
},
single: true
});
else store.load();
},
问题是在我检查 isLoading() 的时间和调用 load() 的时间之间存在一个竞争条件的窗口。
在 ExtJS 中加载 TreeStore 的正确方法是什么,知道它可以稍后重新加载?
When I load my TreeStore a second time before the first load is finished, it fails. TreeStore load() doesn't seem to be reentrant.
So that is what I am doing to make the second load() wait:
loadStore: function(){
var store=this.store;
if (store.isLoading()) this.addListener({
load: function(store,rec,success){
this.loadStore()
},
single: true
});
else store.load();
},
The problem is that there is a window for a race condition between the time I check for isLoading() and the time I call load().
What is the proper way to load a TreeStore in ExtJS, knowing that it can be reloaded later ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
Javascript 在很大程度上是单线程的,所以不应该有任何方法在这些检查之间加载存储,所以我认为你没问题。 Ext 的代码在自己的源代码中进行此类检查,因此它可能是安全的。
我喜欢偶尔阅读这个问题的回答以进行复习关于 JavaScript 线程。
Javascript is, for the most part, single-threaded, so there shouldn't be any way to have the store load in between those checks, so I think you are okay. Ext's code makes these kinds of checks in their own source code, so it is probably safe.
I like to read this question's responses every once in awhile for a refresher on javascript threading.