xenith_sync/subscription.rs
1use xenith_core::{ChainId, StateKey};
2
3/// Handle to a running subscription polling loop.
4///
5/// Dropping or calling [`cancel`][SubscriptionHandle::cancel] stops the loop.
6pub struct SubscriptionHandle {
7 pub key: StateKey,
8 pub source_chain: ChainId,
9 abort_handle: tokio::task::AbortHandle,
10}
11
12impl SubscriptionHandle {
13 pub(crate) fn new(
14 key: StateKey,
15 source_chain: ChainId,
16 abort_handle: tokio::task::AbortHandle,
17 ) -> Self {
18 Self {
19 key,
20 source_chain,
21 abort_handle,
22 }
23 }
24
25 /// Stop the subscription polling loop.
26 pub fn cancel(self) {
27 self.abort_handle.abort();
28 }
29}