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:
@@ -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::*;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user