Just seeking confirmation.
Consider this AngularJs code:
$rootScope.myNeededBoolean = false;
$rootScope.$on('userHasJustBeenAuthenticated', function(){
if(!$rootScope.myNeededBoolean) {
$rootScope.myNeededBoolean = true;
//This ensures that the following piece of code will run only once.
executeOnlyOnce();
}
});
This code is designed to execute a specific block of code when the user logs in.
If two separate codes trigger this simultaneously (using $rootScope.$broadcast, for example) for the same event 'userHasJustBeenAuthenticated' - can it be guaranteed that $rootScope.$on will always be accessed sequentially every time?
Given JavaScript's single-threaded nature, is it certain that $rootScope.myNeededBoolean will serve as a determinant, so that executeOnlyOnce runs only once?