I have the below code. It is written in older version of JS when promises were not available. So, the request being made is an Async operation (XHR request). I want to wait for the async request to complete first and once the value is set properly for user and settings then I want to return the updated user object from the function. Please help me in implementing the scenario.
Thanks
CurrentUser.prototype.getUserSettings = function() {
var self = this;
self.oneloginApiServer.request(
{ url: "/form-service/me", json: true },
function(err, user) {
if (!err) {
self.set(user);
self.setUserSettings(user.userSettings);
} else {
console.error(
"Failed to reinit current user. Using previous:",
self.getUserDebugName(self.user)
);
}
}
);
console.log(
JSON.stringify({ settings: this.settings })
);
return this.getSettings();
};