ExtJS 4:重新加载商店时如何防止竞争条件?

发布于 2024-12-14 04:52:18 字数 494 浏览 4 评论 0原文

当我在第一次加载完成之前第二次加载 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年已逝 2024-12-21 04:52:18

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文