Register a task for the given drain phase. Returns a `DrainGuard` the task must hold until its cleanup is complete. `abort_handle`: if `Some`, the task will be aborted if it misses the budget. Pass `None` for blocking threads.
(
&self,
drain_at: ShutdownPhase,
name: &'static str,
abort_handle: Option<tokio::task::AbortHandle>,
)
| 218 | /// `abort_handle`: if `Some`, the task will be aborted if it misses |
| 219 | /// the budget. Pass `None` for blocking threads. |
| 220 | pub fn register_task( |
| 221 | &self, |
| 222 | drain_at: ShutdownPhase, |
| 223 | name: &'static str, |
| 224 | abort_handle: Option<tokio::task::AbortHandle>, |
| 225 | ) -> DrainGuard { |
| 226 | let mut guard = lock_bus(&self.state); |
| 227 | let id = guard.alloc_id(); |
| 228 | guard.tasks.insert( |
| 229 | id, |
| 230 | TaskEntry { |
| 231 | name, |
| 232 | phase: drain_at, |
| 233 | drained: false, |
| 234 | abort_handle, |
| 235 | }, |
| 236 | ); |
| 237 | let phase_rx = self.phase_tx.subscribe(); |
| 238 | DrainGuard { |
| 239 | task_id: id, |
| 240 | phase: drain_at, |
| 241 | state: Arc::clone(&self.state), |
| 242 | phase_rx, |
| 243 | reported: false, |
| 244 | name, |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /// Initiate graceful shutdown. Idempotent — second call is a no-op. |
| 249 | /// |
no test coverage detected