Skip to content
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

Draft
wants to merge 4 commits into
base: v2
Choose a base branch
from

Conversation

Ludea
Copy link
Contributor

@Ludea Ludea commented Oct 17, 2024

closes #1920

@@ -302,6 +303,20 @@ pub fn kill<R: Runtime>(
Ok(())
}

#[tauri::command]
pub fn wait<R: Runtime>(
Copy link
Contributor

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

Copy link
Contributor Author

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

@@ -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> {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use async fn

Copy link
Contributor

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]
Copy link
Contributor

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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahqsoftwares
Copy link
Contributor

ahqsoftwares commented Oct 18, 2024

Also, you may use tokio::process https://docs.rs/tokio/latest/tokio/process/struct.Command.html instead of std::process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[shell] feat: close event on child process
2 participants