diff --git a/crates/lanspread-peer/src/call_to_play.rs b/crates/lanspread-peer/src/call_to_play.rs index bd9105f..7de9da1 100644 --- a/crates/lanspread-peer/src/call_to_play.rs +++ b/crates/lanspread-peer/src/call_to_play.rs @@ -30,7 +30,12 @@ pub(crate) struct CallToPlayStore { } impl CallToPlayStore { - pub(crate) fn snapshot(&self) -> Vec { + pub(crate) fn snapshot(&mut self) -> Vec { + self.snapshot_at(now_ms()) + } + + fn snapshot_at(&mut self, now: i64) -> Vec { + self.compact_inactive_calls(now); self.events.clone() } @@ -434,8 +439,6 @@ mod tests { .insert(create_event("create")) .expect("active call should fit"); - store.compact_inactive_calls(TEST_NOW + 5 * 60_000 + 60_001); - - assert!(store.snapshot().is_empty()); + assert!(store.snapshot_at(TEST_NOW + 5 * 60_000 + 60_001).is_empty()); } } diff --git a/crates/lanspread-peer/src/lib.rs b/crates/lanspread-peer/src/lib.rs index 3ae9a01..7ea223b 100644 --- a/crates/lanspread-peer/src/lib.rs +++ b/crates/lanspread-peer/src/lib.rs @@ -510,7 +510,7 @@ async fn handle_peer_commands( let _ = reply.send(result); } PeerCommand::GetCallToPlayEvents { reply } => { - let events = ctx.call_to_play.read().await.snapshot(); + let events = ctx.call_to_play.write().await.snapshot(); events::send(tx_notify_ui, PeerEvent::CallToPlayEvents(events.clone())); if let Some(reply) = reply { let _ = reply.send(events); diff --git a/crates/lanspread-peer/src/services/handshake.rs b/crates/lanspread-peer/src/services/handshake.rs index 3a428d2..498de67 100644 --- a/crates/lanspread-peer/src/services/handshake.rs +++ b/crates/lanspread-peer/src/services/handshake.rs @@ -67,7 +67,7 @@ pub(super) async fn build_hello_ack(ctx: &PeerCtx) -> eyre::Result { let library_guard = ctx.local_library.read().await; build_library_snapshot(&library_guard) }; - let call_to_play_events = ctx.call_to_play.read().await.snapshot(); + let call_to_play_events = ctx.call_to_play.write().await.snapshot(); Ok(HelloAck { peer_id: ctx.peer_id.as_ref().clone(), proto_ver: PROTOCOL_VERSION, @@ -84,7 +84,7 @@ async fn build_hello_from_state(ctx: &HandshakeCtx) -> eyre::Result { let library_guard = ctx.local_library.read().await; build_library_snapshot(&library_guard) }; - let call_to_play_events = ctx.call_to_play.read().await.snapshot(); + let call_to_play_events = ctx.call_to_play.write().await.snapshot(); Ok(Hello { peer_id: ctx.peer_id.as_ref().clone(), proto_ver: PROTOCOL_VERSION, @@ -538,7 +538,7 @@ mod tests { .expect("current protocol hello should be accepted"); assert_eq!( - ctx.call_to_play.read().await.snapshot(), + ctx.call_to_play.write().await.snapshot(), [call_to_play_event()] ); assert!(matches!(