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

fix(core): Command::output suspend while wait for response #8539

Merged
merged 3 commits into from
Feb 1, 2024

Conversation

dyxushuai
Copy link
Contributor

@dyxushuai dyxushuai commented Jan 4, 2024

spawn_pipe_reader(
tx.clone(),
guard.clone(),
stdout_reader,
CommandEvent::Stdout,
encoding,
);
spawn_pipe_reader(
tx.clone(),
guard.clone(),
stderr_reader,
CommandEvent::Stderr,
encoding,
);

These two methods will hold the tx(Sender) and never drop them because the method spawn_pipe_reader will be lost in the loop and unable to get out without break;

loop {
buf.clear();
match tauri_utils::io::read_line(&mut reader, &mut buf) {
Ok(n) => {
if n == 0 {
break;
}
let tx_ = tx.clone();
let line = match character_encoding {
Some(encoding) => Ok(encoding.decode_with_bom_removal(&buf).0.into()),
None => String::from_utf8(buf.clone()),
};
block_on_task(async move {
let _ = match line {
Ok(line) => tx_.send(wrapper(line)).await,
Err(e) => tx_.send(CommandEvent::Error(e.to_string())).await,
};
});
}
Err(e) => {
let tx_ = tx.clone();
let _ = block_on_task(async move { tx_.send(CommandEvent::Error(e.to_string())).await });
}
}
}

So, the loop in output method will never receive a None value from Reciver.

while let Some(event) = rx.recv().await {
match event {
CommandEvent::Terminated(payload) => {
code = payload.code;
}
CommandEvent::Stdout(line) => {
stdout.push_str(line.as_str());
stdout.push('\n');
}
CommandEvent::Stderr(line) => {
stderr.push_str(line.as_str());
stderr.push('\n');
}
CommandEvent::Error(_) => {}
}
}

@dyxushuai
Copy link
Contributor Author

Maybe resolves #8572

lucasfernog added a commit to tauri-apps/plugins-workspace that referenced this pull request Jan 31, 2024
@lucasfernog lucasfernog merged commit cc3d8e7 into tauri-apps:1.x Feb 1, 2024
19 checks passed
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.

3 participants