Reload Channel
src/build/reload.rs
The reload channel is a tokio::sync::broadcast channel that carries DevServerMessage values from the server to all connected browser tabs.
Message types
#![allow(unused)] fn main() { pub enum DevServerMessage { Reload, BuildError(String), } }
Flow
- A watcher detects a file change and sends a trigger to the build coordinator
- The build coordinator runs the build
- On success, it sends
DevServerMessage::Reloadon the broadcast channel - On failure, it sends
DevServerMessage::BuildError(message) - The WebSocket handler receives the message and forwards it to the browser
- The browser either reloads or displays the error overlay
WebSocket handler
ws_reload_handler upgrades the HTTP connection to WebSocket and subscribes to the broadcast channel. It handles:
Reload— sends"reload"text frameBuildError— sends"error:<message>"text frameRecvError::Lagged— subscriber fell behind, sends one reloadRecvError::Closed— broadcast channel closed, exits loop- Client disconnect — exits loop cleanly