Skip to content

Commit

Permalink
add process kill function
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwparas committed Dec 28, 2024
1 parent cfe54cc commit 5080857
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/steel-core/src/primitives/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub fn process_module() -> BuiltInModule {
.register_fn("which", binary_exists_on_path)
.register_fn("child-stdout", ChildProcess::stdout)
.register_fn("child-stderr", ChildProcess::stderr)
.register_fn("child-stdin", ChildProcess::stdin);
.register_fn("child-stdin", ChildProcess::stdin)
.register_fn("kill", ChildProcess::kill);

module
}
Expand Down Expand Up @@ -112,6 +113,15 @@ impl ChildProcess {
self.wait_impl().into()
}

pub fn kill(&mut self) -> Result<SteelVal, SteelErr> {
self.child
.take()
.ok_or_else(crate::throw!(Generic => "Child already killed!"))?
.kill()
.map_err(SteelErr::from)
.map(|_| SteelVal::Void)
}

fn wait_with_stdout_impl(&mut self) -> Result<String, SteelErr> {
let stdout = self
.child
Expand Down

0 comments on commit 5080857

Please sign in to comment.