mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-10 06:25:00 +00:00
Wrap BytesFreezer in span
This commit is contained in:
parent
d67478843b
commit
f390c62cbf
1 changed files with 12 additions and 6 deletions
|
@ -33,7 +33,7 @@ pub(crate) struct ProcessRead<I> {
|
||||||
handle: JoinHandle<()>,
|
handle: JoinHandle<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BytesFreezer<S>(S);
|
struct BytesFreezer<S>(S, Span);
|
||||||
|
|
||||||
impl Process {
|
impl Process {
|
||||||
pub(crate) fn run(command: &str, args: &[&str]) -> std::io::Result<Self> {
|
pub(crate) fn run(command: &str, args: &[&str]) -> std::io::Result<Self> {
|
||||||
|
@ -147,7 +147,10 @@ impl Process {
|
||||||
pub(crate) fn bytes_stream(
|
pub(crate) fn bytes_stream(
|
||||||
input: impl AsyncRead + Unpin,
|
input: impl AsyncRead + Unpin,
|
||||||
) -> impl Stream<Item = Result<Bytes, Error>> + Unpin {
|
) -> impl Stream<Item = Result<Bytes, Error>> + Unpin {
|
||||||
BytesFreezer(FramedRead::new(input, BytesCodec::new()))
|
BytesFreezer(
|
||||||
|
FramedRead::new(input, BytesCodec::new()),
|
||||||
|
tracing::info_span!("Serving bytes from AsyncRead"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> AsyncRead for ProcessRead<I>
|
impl<I> AsyncRead for ProcessRead<I>
|
||||||
|
@ -202,10 +205,13 @@ where
|
||||||
type Item = Result<Bytes, Error>;
|
type Item = Result<Bytes, Error>;
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
Pin::new(&mut self.0)
|
let span = self.1.clone();
|
||||||
.poll_next(cx)
|
span.in_scope(|| {
|
||||||
.map(|opt| opt.map(|res| res.map(|bytes_mut| bytes_mut.freeze())))
|
Pin::new(&mut self.0)
|
||||||
.map_err(Error::from)
|
.poll_next(cx)
|
||||||
|
.map(|opt| opt.map(|res| res.map(|bytes_mut| bytes_mut.freeze())))
|
||||||
|
.map_err(Error::from)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue