-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Describe the bug
When using the sidecar to execute long running sub commands, I try to receive new stdout events.
For that I wrote this code:
let (mut rx, mut child) = cmd.spawn().expect("Failed to spawn sidecar");
tauri::async_runtime::spawn(async move {
// read events such as stdout
while let Some(event) = rx.recv().await {
if let CommandEvent::Stdout(line) = event {
debug!("{}", line);
window.emit("upload-progress", Payload {
message: line,
});
}
}
debug!("upload complete");
window.emit("upload-complete", {});
});But the future of rx.recv() is never resolved when spawning a command that clears its output before writing to it again (i.e. human readable progress in a terminal). It only resolves after the child process exited and then it dumps out all the lines at once.
Using a command that doesn't clear out before updating works fine and it seems like, that it also works fine when the command clears out and writes multiple lines.
I encountered that using the rclone sync source:path target:path --progress --progress-terminal-title --stats-one-line command.
Reproduction
- Create an app
- Using sidecar, spawn a long running command that always clears stdout before writing to it
- Try to receive events from command
rx.recv().awaitdoesn't resolve- Wait until command finsihed
rx.recv().awaitresolved with the complete output
Expected behavior
rx.recv().await should resolve for every event during running command
Platform and versions
Operating System - Mac OS, version 11.6.0 X64
Node.js environment
Node.js - 16.13.0
@tauri-apps/cli - 1.0.0-rc.4
@tauri-apps/api - 1.0.0-rc.1
Global packages
npm - 8.1.0
pnpm - Not installed
yarn - 1.22.10
Rust environment
rustup - 1.24.3
rustc - 1.58.1
cargo - 1.58.0
toolchain - stable-x86_64-apple-darwin
App directory structure
/test
/dist
/node_modules
/src-tauri
/.git
/.idea
/src
App
tauri - 1.0.0-rc.2
tauri-build - 1.0.0-rc.2
tao - 0.6.2
wry - 0.13.1
build-type - bundle
CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
distDir - ../dist
devPath - http://local-desktop.syra.live:3000/
framework - React
✨ Done in 9.42s.Stack trace
No response
Additional context
Discussion with @FabianLars about that here in discord: https://discord.com/channels/616186924390023171/731495047962558564/944267064175132732