feat: add SubscriptionHandle for managing subscription lifecycle

- Add SubscriptionHandle struct to manage async subscription tasks
- Implement graceful shutdown mechanism with unsub_fn callback
- Export new module in common/mod.rs
- Support for proper resource cleanup in subscription management
This commit is contained in:
ysq
2025-07-09 22:54:25 +08:00
parent 44ae51747b
commit e0a47a271f
2 changed files with 14 additions and 0 deletions
+1
View File
@@ -3,5 +3,6 @@ pub mod nonce_cache;
pub mod tip_cache;
pub mod types;
pub mod address_lookup_cache;
pub mod subscription_handle;
pub use types::*;
+13
View File
@@ -0,0 +1,13 @@
use tokio::task::JoinHandle;
pub struct SubscriptionHandle {
pub task: JoinHandle<()>,
pub unsub_fn: Box<dyn Fn() + Send>,
}
impl SubscriptionHandle {
pub async fn shutdown(self) {
(self.unsub_fn)();
self.task.abort();
}
}