pub async fn serve(
listener: TcpListener,
metrics: Arc<Metrics>,
shutdown: Receiver<()>,
) -> Result<()>Expand description
Serve /metrics over HTTP on the pre-bound listener until shutdown
fires. The shutdown receiver is consumed; send () to stop the accept
loop.
Per-connection tasks are spawned with tokio::spawn and detached —
they are not tracked or awaited during shutdown. In practice scrapes
complete in milliseconds, and dropping an in-flight /metrics response
is harmless (the scraper will retry on its next interval). This is a
deliberate choice: tracking an unbounded JoinSet alongside the accept
loop would add complexity without a consumer that cares about the
guarantee.