Skip to main content

vv_agent/runtime/background_sessions/
subscription.rs

1use super::{background_session_manager, BackgroundSessionManager};
2
3pub struct BackgroundSessionSubscription {
4    session_id: String,
5    listener_id: Option<u64>,
6    manager: &'static BackgroundSessionManager,
7}
8
9impl BackgroundSessionSubscription {
10    pub(in crate::runtime::background_sessions) fn new(
11        session_id: String,
12        listener_id: u64,
13        manager: &'static BackgroundSessionManager,
14    ) -> Self {
15        Self {
16            session_id,
17            listener_id: Some(listener_id),
18            manager,
19        }
20    }
21
22    pub(in crate::runtime::background_sessions) fn noop() -> Self {
23        Self {
24            session_id: String::new(),
25            listener_id: None,
26            manager: background_session_manager(),
27        }
28    }
29
30    pub fn unsubscribe(mut self) {
31        if let Some(listener_id) = self.listener_id.take() {
32            self.manager.unsubscribe(&self.session_id, listener_id);
33        }
34    }
35}
36
37impl Drop for BackgroundSessionSubscription {
38    fn drop(&mut self) {
39        if let Some(listener_id) = self.listener_id.take() {
40            self.manager.unsubscribe(&self.session_id, listener_id);
41        }
42    }
43}