Run world service policy in WASI init with pollable process observation

This commit is contained in:
2026-11-06 19:49:19 +00:00
parent b5462cc366
commit b39bbd4f18
21 changed files with 1821 additions and 224 deletions
+19
View File
@@ -41,11 +41,14 @@ mod bindings {
with: {
"wasi:io": wasmtime_wasi::p2::bindings::io,
"sausage:process/host.child": super::Child,
"sausage:process/host.watcher": super::Watcher,
},
});
}
use bindings::sausage::process::host::{Host, HostChild, Request, Stdio};
mod services;
mod watcher;
pub use watcher::Watcher;
mod stdio;
pub use services::supervise;
use stdio::Io;
@@ -470,7 +473,23 @@ impl Host for State {
Ok(self.runtime.kill_pid(pid).map_err(|e| e.to_string()))
}
}
#[async_trait::async_trait]
impl wasmtime_wasi::p2::Pollable for Child {
async fn ready(&mut self) {
while self.code.borrow_and_update().is_none() {
if self.code.changed().await.is_err() {
break;
}
}
}
}
impl HostChild for State {
async fn subscribe(
&mut self,
child: Resource<Child>,
) -> wasmtime::Result<Resource<wasmtime_wasi::p2::DynPollable>> {
wasmtime_wasi::p2::subscribe(&mut self.table, child)
}
async fn pid(&mut self, child: Resource<Child>) -> wasmtime::Result<u32> {
Ok(self.table.get(&child)?.pid)
}