-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(shell) add wait fn to get event from child process #1947
base: v2
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ use crate::{ | |
scope::ExecuteArgs, | ||
Shell, | ||
}; | ||
use std::process::ExitStatus; | ||
|
||
type ChildId = u32; | ||
|
||
|
@@ -302,6 +303,20 @@ pub fn kill<R: Runtime>( | |
Ok(()) | ||
} | ||
|
||
#[tauri::command] | ||
pub fn wait<R: Runtime>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will block the whole app to wait for the process There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use async to avoid blocking thread |
||
_window: Window<R>, | ||
shell: State<'_, Shell<R>>, | ||
pid: ChildId, | ||
) -> crate::Result<ExitStatus> { | ||
if let Some(child) = shell.children.lock().unwrap().get(&pid) { | ||
let exitstatus: ExitStatus = child.wait()?; | ||
Ok(exitstatus) | ||
} else { | ||
Err(crate::Error::UnknowChildProcess) | ||
} | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn open<R: Runtime>( | ||
_window: Window<R>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,12 @@ impl CommandChild { | |
pub fn pid(&self) -> u32 { | ||
self.inner.id() | ||
} | ||
|
||
/// Waits for the child to exit completely, returning the status that it exited with. | ||
pub fn wait(self) -> crate::Result<std::process::ExitStatus> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will block the whole app to wait for the process to exit, we need to use something async / non blocking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use async fn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. async fn will also block it |
||
let exitstatus = self.inner.wait()?; | ||
Ok(exitstatus) | ||
} | ||
} | ||
|
||
/// Describes the result of a process after it has terminated. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use try_wait and if it's ready then wait for the response