简体   繁体   English

任何调用$ q通知的方式都不会导致$ digest循环吗?

[英]Any way to call $q notify without causing $digest cycle?

I have an app that $digest cycle takes about 5ms, and I am using $q.defer with deferred.notify a lot inside my app. 我有一个应用程序,$ digest周期大约需要5毫秒,并且我在$q.deferdeferred.notify了很多应用程序。 The issue is that every time deferred.notify is called, a digest cycle will be scheduled, and cause angular running it for 5ms. 问题在于,每次调用deferred.notify ,都会安排一个摘要周期,并导致它在角度上运行5ms。

As a result, when I fetching few thousands rows of data from server (through WebSocket, the data are received one by one), the app can use 100% CPU and become very unresponsive. 结果,当我从服务器获取数千行数据时(通过WebSocket,数据被一一接收),该应用程序可能会占用100%的CPU,并且变得非常无响应。 The only thing I do with those data is save them into IndexedDB. 我对这些数据所做的唯一一件事就是将它们保存到IndexedDB中。

Is any way to use $q and notify without schedule a $digest cycle? 有什么方法可以使用$q并在没有调度的情况下notify $ digest周期?

I am thinking using a different promise implementation for WebSocket and IndexedDB related code, but I don't like the idea to have two promise implementations and it is almost impossible to know which kind of promise will be returned after a long chain. 我正在考虑对WebSocket和IndexedDB相关的代码使用不同的Promise实现,但是我不喜欢有两个Promise实现的想法,而且几乎不可能知道长链之后将返回哪种Promise。

You could use a different promise implementation, or really that sounds a lot like a job for RxJS . 您可以使用其他的promise实现,或者实际上听起来很像RxJS的工作。 A non-angular promise like the browser-native version or Bluebird wouldn't trigger digest cycles on all notifies. 像浏览器原生版本或Bluebird这样的非角度承诺不会触发所有通知的摘要周期。 Then you'd just have to manually digest stuff - this is what I do: I use RxJS to process websocket events and manually call scope.$apply on appropriate scopes occasionally when needed (as you - I don't need to update my scopes on every websocket event). 然后您只需要手动消化内容-这就是我的工作:我使用RxJS处理websocket事件并手动调用scope。$有时在需要时在适当的范围上应用(因为您-我不需要更新自己的范围在每个websocket事件中)。

I just found $$q . 我刚发现$$ q From what I understand, it is $q without digest cycle which is exactly what I want. 据我了解,正是$ q没有摘要周期,这正是我想要的。

However it is an undocumented private service. 但是,这是无证的私人服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM