Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs deferred log-running timer task(s)

Building an Ionic app and have suddenly come across an issue that I am finding really difficult to debug where the browser is 'deferring' long running timer tasks causing my views to execute the code in their controllers only once (even when the controller is explicitly reloaded).

Warning is:

Deferred long-running timer task(s) to improve scrolling smoothness. See crbug.com/574343.

What I'm after:

  • An understanding of the warning and why it occurs
  • Any guidance as to how to go about debugging such a warning.

Thanks in advance.

Update I felt it was important to note that while never receiving errors and only warnings as the cause for my problems, I have since rolled back to a working version.

This working version still has warnings appearing but does not affect the running of my application.

like image 772
Vince Avatar asked Apr 20 '16 06:04

Vince


People also ask

How to use defer in AngularJS?

Simply put you can use $q. defer() to create a Promise. A Promise is a function that returns a single value or error in the future. So whenever you have some asynchronous process that should return a value or an error, you can use $q.

What is$ q service in Angular?

$q is integrated with the $rootScope. Scope Scope model observation mechanism in AngularJS, which means faster propagation of resolution or rejection into your models and avoiding unnecessary browser repaints, which would result in flickering UI. Q has many more features than $q, but that comes at a cost of bytes.

What is Q defer ()?

We can use $q to defer operations to the future while having a pending promise object at the present, by using $q. defer we create a promise that will either resolve or reject in the future. This method is not equivalent of using the $q constructor, as we use $q.


Video Answer


1 Answers

well in case when you are doing tasks using $timeout , you have got to stop and destroy them else they would create the error you stated

for eg:

var timer = $timeout(                         function() {                             console.log( "Timeout executed", Date.now() );                         },                         2000                     ); 

if you start a timeout as above then you got to destroy the timer as follows :

                    // When the DOM element is removed from the page,                     // AngularJS will trigger the $destroy event on                     // the scope. This gives us a chance to cancel any                     // pending timer that we may have. $scope.$on(                         "$destroy",                         function( event ) {                             $timeout.cancel( timer );                         }                     ); 
like image 87
Vishal Wadhawan Avatar answered Oct 14 '22 12:10

Vishal Wadhawan