Skip to content

Commit

Permalink
Merge pull request #543 from badoo/fix_double_completion_execution_wi…
Browse files Browse the repository at this point in the history
…th_fast_updates_enabled

Returned protection against double completion execution during updates
  • Loading branch information
AntonPalich authored Jan 8, 2019
2 parents 174ba83 + ef8c726 commit 4bd36df
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Chatto/Source/ChatController/BaseChatViewController+Changes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ extension BaseChatViewController {
}
}

let myCompletion: () -> Void
do { // Completion
var myCompletionExecuted = false
myCompletion = {
if myCompletionExecuted { return }
myCompletionExecuted = true
completion()
}
}

if usesBatchUpdates {
UIView.animate(withDuration: self.constants.updatesAnimationDuration, animations: { () -> Void in
self.unfinishedBatchUpdatesCount += 1
Expand All @@ -186,7 +196,7 @@ extension BaseChatViewController {
collectionView.moveItem(at: move.indexPathOld, to: move.indexPathNew)
}
}, completion: { [weak self] (_) -> Void in
defer { completion() }
defer { myCompletion() }
guard let sSelf = self else { return }
sSelf.unfinishedBatchUpdatesCount -= 1
if sSelf.unfinishedBatchUpdatesCount == 0, let onAllBatchUpdatesFinished = self?.onAllBatchUpdatesFinished {
Expand Down Expand Up @@ -216,7 +226,7 @@ extension BaseChatViewController {
}

if !usesBatchUpdates || self.updatesConfig.fastUpdates {
completion()
myCompletion()
}
}

Expand Down

0 comments on commit 4bd36df

Please sign in to comment.