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

refactor(shell): Use &self instead of self to allow kill to be called multiple times. #2224

Open
wants to merge 5 commits into
base: v2
Choose a base branch
from

Conversation

xuchaoqian
Copy link

@xuchaoqian xuchaoqian commented Dec 19, 2024

Description

This refactor modifies the kill method in the CommandChild struct to take a reference (&self) instead of consuming the instance (self). This change allows the kill method to be called multiple times on the same CommandChild instance, providing more flexibility in managing child processes.

Use Case

use tauri_plugin_shell::process::Command;
use std::time::Duration;
use std::thread::sleep;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a new command to run a long-running process
    let process = Command::new("sleep").arg("10").spawn()?;

    // Attempt to kill the process multiple times in a loop
    loop {
        process.kill()?;
        // Do something to check if the process still exists?
        // ...
        sleep(Duration::from_secs(1));
    }

    Ok(())
}

@xuchaoqian xuchaoqian requested a review from a team as a code owner December 19, 2024 06:20
Copy link
Contributor

github-actions bot commented Dec 19, 2024

Package Changes Through dd59321

There are 1 changes which include shell with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
api-example 2.0.11 2.0.12
shell 2.2.0 2.2.1

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

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.

1 participant