I am curious about some aspects of the code snippet provided below:
getRemoteProfile
seems to returnPromise.resolve
only under specific conditions, but what happens if that condition fails sincegetRemoteProfile
calls are always chained withthen
?Can you explain the difference between
return promise
andreturn promise.resolve
? It appears thatreturn promise.resolve
always leads to the execution ofthen
.function getRemoteProfile(id) { if (!id && /^_/.test(id)) { return Promise.resolve(null); } var isGroup = app.isGroupId(id); if (isGroup) { return getGroupInfo(id); } else { return getUserInfo(id.split('@')[0], app.currentUserDomain); } } function reloadProfile(id, keep) { return getRemoteProfile(id).then(function(contactProfile) { // var isGroup = app.isGroupId(id); if (contactProfile) { contactProfile.contact_id = id; if (!keep) { delete profilePromises[id]; } contactProfile.member = true; updateProfile(contactProfile.contact_id, contactProfile).then(function() { app.imagesStorage.setContactIcon(contactProfile.contact_id); }); return setDetails(contactProfile); } }); }