Skip to content

Commit

Permalink
Reject all stored promises on conversation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Herdmann committed May 4, 2017
1 parent c56b4c3 commit f304ebe
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/script/conversation/ConversationRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ z.conversation.ConversationRepository = class ConversationRepository {
*/
fetch_conversation_by_id(conversation_id) {
if (this.fetching_conversations.hasOwnProperty(conversation_id)) {
return new Promise((resolve) => {
this.fetching_conversations[conversation_id].push(resolve);
return new Promise((resolve, reject) => {
this.fetching_conversations[conversation_id].push({reject_fn: reject, resolve_fn: resolve});
});
}

Expand All @@ -183,15 +183,22 @@ z.conversation.ConversationRepository = class ConversationRepository {
this.logger.info(`Fetched conversation '${conversation_id}' from backend`);
this.save_conversation(conversation_et);

this.fetching_conversations[conversation_id].forEach(function(resolve_fn) {
this.fetching_conversations[conversation_id].forEach(function({resolve_fn}) {
resolve_fn(conversation_et);
});
delete this.fetching_conversations[conversation_id];

return conversation_et;
})
.catch(function() {
throw new z.conversation.ConversationError(z.conversation.ConversationError.TYPE.NOT_FOUND);
const error = new z.conversation.ConversationError(z.conversation.ConversationError.TYPE.NOT_FOUND);

this.fetching_conversations[conversation_id].forEach(function({reject_fn}) {
reject_fn(error);
});
delete this.fetching_conversations[conversation_id];

throw error;
});
}

Expand Down

0 comments on commit f304ebe

Please sign in to comment.