AngularJs or JavaScript Wait For Some Condition

At one line of my code I have something like that:

...
while(!$scope.isMyTurn(privilege)){}
I will run next line of codes

However as usual it blocks my browser. I have to wait until get true to run next line of codes. I don't want to block my browser and other functionalities should work because(some of other fired events will change the situation of my turn) User should continue whatever he does.

This is for refreshing a graphic until my turn is come.

Consider using the $scope.$watch function.

Look under ($watch): http://docs.angularjs.org/api/ng.$rootScope.Scope

You should be doing it something like :

$scope.$watch("isMyTurn(privilege)",function(val){
    if(val){
       //I will run next line of codes
    }
});

instead of what you are attempting to do.. Note that in this scenario, privilege should also be a scope variable something like

$scope.privilege

If you dont want it to be a scope variable just dont pass it as an argument. but directly access it inside the function..

Hope this helps..

I don't know about angularJS but in normal JavaScript you could use setTimeout

function whenReady()
{
  if ($scope.isMyTurn(privilege)){
    I will run next line of codes
  }
  else
  {
    window.setTimeout(whenReady, 1000);
  }
}
window.setTimeout(whenReady, 1000);