pub async fn run_reload_server(host: String, port: u16) {
    // Parse `localhost` into `127.0.0.1` (picky Rust `std`)
    let host = if host == "localhost" {
        "127.0.0.1".to_string()
    } else {
        host
    };
    // Parse the host and port into an address
    let addr: SocketAddr = format!("{}:{}", host, port).parse().unwrap();

    let clients = Clients::default();
    let clients = warp::any().map(move || clients.clone());

    // This will be used by the CLI to order reloads
    let command = warp::path("send")
        .and(clients.clone())
        .then(|clients: Clients| async move {
            // Iterate through all the clients and tell them all to reload
            for (_id, tx) in clients.read().await.iter() {
                // We don't care if this fails, that means the client has disconnected and the
                // disconnection code will be running
                let _ = tx.send(Message::text("reload"));
            }

            "sent".to_string()
        });
    // This will be used by the browser to listen for reload orders
    let receive = warp::path("receive").and(warp::ws()).and(clients).map(
        |ws: warp::ws::Ws, clients: Clients| {
            // This code will run once the WS handshake completes
            ws.on_upgrade(|ws| async move {
                // Assign a new ID to this user
                // This nifty operation just gets the current value and then increments
                let id = NEXT_UID.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
                // Split out their sender/receiver
                let (mut ws_tx, mut ws_rx) = ws.split();
                // Use an unbounded channel as an intermediary to the WebSocket
                let (tx, rx) = unbounded_channel();
                let mut rx = UnboundedReceiverStream::new(rx);
                tokio::task::spawn(async move {
                    // Whenever a message come sin on that intermediary channel, we'll just relay it
                    // to the client
                    while let Some(message) = rx.next().await {
                        let _ = ws_tx.send(message).await;
                    }
                });

                // Save the sender and their intermediary channel
                clients.write().await.insert(id, tx);

                // Because we don't accept messages from listening clients, we'll just hold a
                // loop until the client disconnects Then, this will become
                // `None` and we'll move on
                while ws_rx.next().await.is_some() {
                    continue;
                }

                // Once we're here, the client has disconnected
                clients.write().await.remove(&id);
            })
        },
    );

    let routes = command.or(receive);
    warp::serve(routes).run(addr).await
}
Runs the reload server, which is used to instruct the browser on when to
reload for updates.
packages/perseus-cli/src/reload_server.rs