-
Notifications
You must be signed in to change notification settings - Fork 282
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?
Conversation
plugins/shell/src/commands.rs
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I use async to avoid blocking thread
plugins/shell/src/process/mod.rs
Outdated
@@ -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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
async fn will also block it
@@ -302,6 +302,19 @@ pub fn kill<R: Runtime>( | |||
Ok(()) | |||
} | |||
|
|||
#[tauri::command] |
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
@@ -84,6 +84,14 @@ 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 async fn wait(self) -> crate::Result<ExitStatus> { |
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.
Also, you may use tokio::process https://docs.rs/tokio/latest/tokio/process/struct.Command.html instead of std::process |
closes #1920