The WorkerHost struct manages the lifecycle of a Nix worker process. It uses a background thread to communicate with a worker binary via stdin and stdout.
To use it, call WorkerHost::new(expr) with a Nix expression. This returns a host containing two channels:
tx: A kanal::Sender<BrowserPath> used to send new paths (expressions) to the worker for inspection.rx: A kanal::Receiver<(BrowserPath, PathData)> used to receive the results of those inspections.
When a path is sent via tx, the receiver will first emit a PathData::Loading state for that path, followed by either the parsed NixValue or a PathData::Error if the inspection fails.
// Example conceptual usage
let host = WorkerHost::new("builtins.attrset".to_string());
// Send a path to inspect
host.tx.send(some_browser_path).unwrap();
// Receive the result
if let Ok((path, data)) = host.rx.recv() {
match data {
PathData::Loading => println!("Loading..."),
PathData::Error(e) => eprintln!("Error: {}", e),
_ => println!("Received data for {:?}", path),
}
}