I have the following code:
var service = {
startSetup: function() {
//If not logged in, redirect to login page
console.log('starting setup, checking login status');
return LoginService.loginStatus().then(function(result) {
var isGrantedPermissionToRoom = result.data.grantedAccess;
if (!isGrantedPermissionToRoom) {
$window.location = $window.location + '/login';
} else {
console.log('setting up room');
return service.setupRoom();
}
});
},
setupRoom: function() {
return RoomStateService.getRoomState().then(function() {
return UserService.getInitialUsersList();
});
}
};
return service;
I want startSetup to return the promise from UserService.getInitialUsersList
after everything before it is complete.
My calling code is:
SetupService.startSetup().then(function() {
console.log('Checking connection to room');
$scope.checkConnectionToRoom(UserService.myUserInfo)
}
and the code for `UserService.getInitialUsersList' is:
getInitialUsersList: function() {
console.log('Getting initial users list');
var deferred = $q.defer();
service.getUserList().then(function(results) {
var newUserList = results.data.results;
updateLocalUserList(newUserList);
updateMyInformation();
HandsUpService.processAllUsers(newUserList);
deferred.resolve();
});
return deferred.promise;
}
I'm aware that I'm not handling rejections yet, but this isn't the problem. It seems that very occasionally UserService.getInitialUsersList
isn't being run fully/at all when control is passed back to the calling code.
Am I returning the chain of promises correctly to the calling code?
Thanks