Skip to content

Commit

Permalink
Flush to stderr not stdout
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
  • Loading branch information
rylev committed Sep 26, 2023
1 parent 3628a8b commit 75f5d62
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crates/trigger/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ impl AsyncWrite for ComponentStdioWriter {
Ok(e) => e,
Err(e) => return Poll::Ready(Err(e)),
};
this.state = ComponentStdioWriterState::Follow(0..written);
if this.follow {
this.state = ComponentStdioWriterState::Follow(0..written);
} else {
return Poll::Ready(Ok(written));
}
}
ComponentStdioWriterState::Follow(range) => {
let written = futures::ready!(std::pin::Pin::new(&mut tokio::io::stdout())
let written = futures::ready!(std::pin::Pin::new(&mut tokio::io::stderr())
.poll_write(cx, &buf[range.clone()]));
let written = match written {
Ok(e) => e,
Expand Down Expand Up @@ -207,7 +211,7 @@ impl AsyncWrite for ComponentStdioWriter {
std::pin::Pin::new(&mut this.async_file).poll_flush(cx)
}
ComponentStdioWriterState::Follow(_) => {
std::pin::Pin::new(&mut tokio::io::stdout()).poll_flush(cx)
std::pin::Pin::new(&mut tokio::io::stderr()).poll_flush(cx)
}
}
}
Expand All @@ -222,7 +226,7 @@ impl AsyncWrite for ComponentStdioWriter {
std::pin::Pin::new(&mut this.async_file).poll_shutdown(cx)
}
ComponentStdioWriterState::Follow(_) => {
std::pin::Pin::new(&mut tokio::io::stdout()).poll_flush(cx)
std::pin::Pin::new(&mut tokio::io::stderr()).poll_flush(cx)
}
}
}
Expand Down

0 comments on commit 75f5d62

Please # to comment.