Spawn an async loop on the tokio runtime. The `body` closure receives a [`ShutdownReceiver`] it MUST select on to observe shutdown. Example: ```ignore use crate::control::shutdown::spawn_loop; spawn_loop( &shared.loop_registry, &shared.shutdown, "wal_catchup", |mut shutdown| async move { let mut tick = tokio::time::interval(Duration::from_millis(50)); loop { tokio::select! { _ = shutdown.wait_c
(
registry: &LoopRegistry,
shutdown: &ShutdownWatch,
name: &'static str,
body: F,
)
| 50 | /// the caller can meaningfully handle, because a registration |
| 51 | /// race means shutdown has already fired. |
| 52 | pub fn spawn_loop<F, Fut>( |
| 53 | registry: &LoopRegistry, |
| 54 | shutdown: &ShutdownWatch, |
| 55 | name: &'static str, |
| 56 | body: F, |
| 57 | ) where |
| 58 | F: FnOnce(ShutdownReceiver) -> Fut + Send + 'static, |
| 59 | Fut: Future<Output = ()> + Send + 'static, |
| 60 | { |
| 61 | let rx = shutdown.subscribe(); |
| 62 | let handle = tokio::spawn(async move { body(rx).await }); |
| 63 | if let Err(e) = registry.register(name, LoopHandle::Async(handle)) { |
| 64 | tracing::warn!( |
| 65 | error = %e, |
| 66 | "spawn_loop after registry close — task will run to completion \ |
| 67 | but shutdown_all will not wait for it" |
| 68 | ); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /// Spawn a blocking loop via `tokio::task::spawn_blocking`. |
| 73 | /// Same semantics as [`spawn_loop`] except the body runs on a |
no test coverage detected