supabase_realtime_rs/infrastructure/
task_manager.rs1use tokio::task::JoinHandle;
2
3pub struct TaskManager {
5 handles: Vec<JoinHandle<()>>,
6}
7
8impl TaskManager {
9 pub fn new() -> Self {
11 Self {
12 handles: Vec::new(),
13 }
14 }
15
16 pub fn spawn<F>(&mut self, future: F)
18 where
19 F: std::future::Future<Output = ()> + Send + 'static,
20 {
21 let handle = tokio::spawn(future);
22 self.handles.push(handle);
23 }
24
25 pub async fn shutdown(self) {
27 for handle in self.handles {
28 handle.abort();
29 let _ = handle.await;
31 }
32 }
33
34 pub fn abort_all(&mut self) {
36 for handle in &self.handles {
37 handle.abort();
38 }
39 self.handles.clear();
40 }
41}
42
43impl Default for TaskManager {
44 fn default() -> Self {
45 Self::new()
46 }
47}