Skip to content

Commit 89f2483

Browse files
committed
fix(spaces): mitigate eventual race conditions when updating the pagination state (part #2)
1 parent 74fd754 commit 89f2483

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

crates/matrix-sdk-ui/src/spaces/room_list.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use std::sync::Arc;
1616

17-
use eyeball::{SharedObservable, Subscriber};
17+
use eyeball::{ObservableWriteGuard, SharedObservable, Subscriber};
1818
use eyeball_im::{ObservableVector, VectorSubscriberBatchedStream};
1919
use futures_util::pin_mut;
2020
use imbl::Vector;
@@ -192,17 +192,21 @@ impl SpaceRoomList {
192192
/// Ask the list to retrieve the next page if the end hasn't been reached
193193
/// yet. Otherwise it no-ops.
194194
pub async fn paginate(&self) -> Result<(), Error> {
195-
match *self.pagination_state.read() {
196-
SpaceRoomListPaginationState::Idle { end_reached } if end_reached => {
197-
return Ok(());
198-
}
199-
SpaceRoomListPaginationState::Loading => {
200-
return Ok(());
195+
{
196+
let mut pagination_state = self.pagination_state.write();
197+
198+
match *pagination_state {
199+
SpaceRoomListPaginationState::Idle { end_reached } if end_reached => {
200+
return Ok(());
201+
}
202+
SpaceRoomListPaginationState::Loading => {
203+
return Ok(());
204+
}
205+
_ => {}
201206
}
202-
_ => {}
203-
}
204207

205-
self.pagination_state.set_if_not_eq(SpaceRoomListPaginationState::Loading);
208+
ObservableWriteGuard::set(&mut pagination_state, SpaceRoomListPaginationState::Loading);
209+
}
206210

207211
let mut request = get_hierarchy::v1::Request::new(self.parent_space_id.clone());
208212
request.max_depth = Some(uint!(1)); // We only want the immediate children of the space

0 commit comments

Comments
 (0)