Broker exit request and nix run .#loop for self-updating hosts
- broker: `{"type":"exit"}` answers `exiting`; `sausage run` then stops all
actors and exits with code 75.
- flake: apps `loop` / `loop-internal` run `nix run --refresh git+ssh://.../surma/sausage -- run <world>`
in a loop; exit code 0 (/quit) ends the loop, anything else restarts.
- PROTOCOL.md, README.md, test in cli/tests/host.rs.
Not compiled: written by the Sausage agent, which cannot build the native host.
This commit is contained in:
+12
-1
@@ -92,9 +92,20 @@ async fn init(dir: PathBuf) -> Result<()> {
|
||||
async fn run(dir: PathBuf) -> Result<()> {
|
||||
let host = Host::start(&dir).await?;
|
||||
tokio::spawn(console::run_mailbox(host.mailbox(console::ID)));
|
||||
console::run_input(host.broker.clone()).await;
|
||||
let broker = host.broker.clone();
|
||||
let exit = tokio::select! {
|
||||
_ = console::run_input(host.broker.clone()) => false,
|
||||
_ = broker.exit_requested() => true,
|
||||
};
|
||||
println!("Stopping actors …");
|
||||
host.stop().await;
|
||||
if exit {
|
||||
// The console still blocks on a stdin read that cannot be cancelled,
|
||||
// so the runtime would not shut down on its own. Exit code 75 tells
|
||||
// `nix run .#loop` to start the host again (0 = /quit = stop the loop).
|
||||
println!("Exiting, as an actor asked the broker to.");
|
||||
std::process::exit(75);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user