Merge branch 'lists-fix-concurrent-sorts' into 'master'

[Lists] Add sort lock

See merge request famedly/famedlysdk!92
This commit is contained in:
Christian Pauly 2019-10-01 09:39:15 +00:00
commit ea83718682
2 changed files with 15 additions and 1 deletions

View file

@ -166,9 +166,14 @@ class RoomList {
sortAndUpdate(); sortAndUpdate();
} }
bool sortLock = false;
sort() { sort() {
if (sortLock) return;
sortLock = true;
rooms?.sort((a, b) => rooms?.sort((a, b) =>
b.timeCreated.toTimeStamp().compareTo(a.timeCreated.toTimeStamp())); b.timeCreated.toTimeStamp().compareTo(a.timeCreated.toTimeStamp()));
sortLock = false;
} }
sortAndUpdate() { sortAndUpdate() {

View file

@ -119,9 +119,18 @@ class Timeline {
} }
} }
sortAndUpdate() { bool sortLock = false;
sort() {
if (sortLock) return;
sortLock = true;
events events
?.sort((a, b) => b.time.toTimeStamp().compareTo(a.time.toTimeStamp())); ?.sort((a, b) => b.time.toTimeStamp().compareTo(a.time.toTimeStamp()));
sortLock = false;
}
sortAndUpdate() {
sort();
if (onUpdate != null) onUpdate(); if (onUpdate != null) onUpdate();
} }
} }