0

I have several functions attached to ng-click directive. The first function filters the list of items and is a a directive scope function, while the second method filters and puts markers on the map and it is the method from the controller. The problem is that the second method from the controller executes about 2 seconds and blocks the execution of the first scope function. Code sample :

<li ng-click="setFilter('favorite'); map.citiesFilter({favorite : true});">Best cities</li>

This method from the controller

map.citiesFilter({favorite : true});

executes 2 seconds and blocks the scope function

setFilter('favorite');

Am I doing somehing wrong, or is there any way to execute this functions asynchronously, so that user won't wait until heavy map filter method from controller ends executing.

6
  • 1
    What's inside the method? If it performs all sync operations then it'll be sync Commented Dec 3, 2014 at 21:10
  • @tymeJV Sorry I've got it wrong. Method from the controller is a part of controller scope. Probably that is causing the issue? Commented Dec 3, 2014 at 21:13
  • 1
    when you say asynchronously do you mean concurrently? because web browsers only allow one thread / process to execute per tab...this thread is either servicing javascript code or browser rendering...therefore when your javascript executes it prevents any other javascript from running and the browser from rerendering Commented Dec 3, 2014 at 21:19
  • @LoganMurphy So basically digest cycle won't run till all methods inside ng directive will execute? Commented Dec 3, 2014 at 21:24
  • 1
    yes, the digest cycle won't run until all blocking code is executed...another thing about javascript - once javascript code is set to execute, it executes until it finishes, since there is no scheduler no other javscript will be given a chance to execute...using $interval, $timeout, and $http services might look concurrent but in reality it is just delaying more blocking javascript code until all other blocking javascript code has been handled Commented Dec 3, 2014 at 21:31

1 Answer 1

1

I think you are confusing asynchronously with concurrently.

Web browsers only allow one thread / process to execute per tab. This thread / process is either servicing javascript code or browser rendering therefore when your javascript executes it prevents any other javascript from running and the browser from rerendering

This means the angular digest cycle won't run until all blocking code is executed.

Another important thing about javascript is once javascript code is set to execute, it runs until it finishes. Since there is no scheduler no other javscript will be given a chance to execute. Using $interval, $timeout, and $http services might look concurrent but in reality they are just delaying more blocking javascript code until all other blocking javascript code has been completely executed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.