Angularjs中止​​承诺仍​​然耽误其他承诺 [英] Angularjs aborted promises still delay other promises

查看:131
本文介绍了Angularjs中止​​承诺仍​​然耽误其他承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发布<一个href=\"http://stackoverflow.com/questions/24440177/angularjs-how-to-cancel-resource-promise-when-switching-routes\">this问题并想出了直接的解决方案(即幸福,我能取消的承诺/请求时的路径改变)。不过,我遇到了,我认为在一个单独的问题属于所以在这里它去另一个相关的问题:

I recently posted this question and figured out the direct solution (that being, I was able to cancel a promise/request when the route changed). However, I'm encountering another, related problem that I think belongs in a separate question so here it goes:

我能放弃我的诺言,当路由变化就好了(你可以从我挂的问题看)。但是,对于一些奇怪的原因,其他航线上的任何其他请求被解析时推迟。看到我的开发工具下面的截图。

I'm able to abort my promise when the route changes just fine (as you can see from the question I linked). However, for some strange reason, any other requests on the other route are delayed when resolving. See my dev tools screenshot below.

下面的情景:我加载路线A,这使得调用 / API /类别键,你可以看到它采用30毫秒这是正常的。然后,我浏览到路径B,那么之前它完成装载我回到路线答:当我返回时,调用 / API / categorySites / 1 被取消,并且可以当看到这种情况发生的灰色栏结束。这是通过中止承诺完成的。然而,回到路线一遍,调用 / API /类别不能解决,直到灰点再次出现在已取消的请求。这第二次调用 / API /类别不应该2.23s,它应该是更接近至30ms。

Here's the scenario: I load route A, which makes the call to /api/categories and you can see it takes 30ms which is normal. Then I navigate to route B, then before it's done loading I return to route A. When I return, the call to /api/categorySites/1 is cancelled, and you can see when that happens as the gray bar ends. This is done by aborting the promise. However, back on route A again, the call to /api/categories doesn't resolve until that gray dot appears again on the request that was cancelled. That second call to /api/categories shouldn't take 2.23s, it should be closer to 30ms.

这是怎么回事?我想第二个请求路由会像以前一样快。我需要得到这个工作得更快。我的code是在<一个href=\"http://stackoverflow.com/questions/24440177/angularjs-how-to-cancel-resource-promise-when-switching-routes\">this问题。让我知道,如果你觉得我应该再包含在这里。这是我很难想象这是不是一个普遍的问题太...

What's going on here? I would think the second Route A request would be just as fast as before. I need to get this to work faster. My code is in this question. Let me know if you think I should include it again here. It's hard for me to imagine this isn't a common problem too...

推荐答案

这是一个老的文章,但我没有看这个,这听起来像渴望与我Emberjs文档中最近读到懒惰的非同步过渡。在你的路由(以及随后中止)履行承诺(完成),以及您重新路由请求移动。

This is an older post but I did look into this and this sounds like eager vs. lazy asynch transition that I read about in Emberjs documentation recently. On your routes (and subsequent aborts) fulfills the promise (completes), moves along to your re-route request.

我相信这可以用状态控制器加以改进。

I believe this can be improved with a state controller.

有一个Angularjs UI路由器状态控制器,可能是使用的。

这里有例子的例子。

Angularjs路由文档(为后人)。

所以这是关于 $ routeProvider (Angularjs默认)由 $ stateProvider 增强(UI路由器)加快中止的路线。

So this is about $routeProvider (Angularjs default) enhanced by $stateProvider (ui-router) to expedite aborted routes.

希望这是有帮助的(大约312天更高版本)。

Hope this is helpful (roughly 312 days later).

这篇关于Angularjs中止​​承诺仍​​然耽误其他承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆