Skip to content

Commit

Permalink
chore: add recv error type (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengys1996 authored Nov 26, 2024
1 parent 4fd293a commit 4de657c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::num::TryFromIntError;

use snafu::Location;
use snafu::Snafu;
use tokio::sync::oneshot::error::RecvError;

#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
Expand Down Expand Up @@ -134,6 +135,13 @@ pub enum Error {
#[snafu(implicit)]
location: Location,
},

#[snafu(display("Failed to recv msg from oneshot channel"))]
Recv {
source: RecvError,
#[snafu(implicit)]
location: Location,
},
}

pub type Result<T> = std::result::Result<T, Error>;
Expand Down
8 changes: 6 additions & 2 deletions src/producer/prealloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::task::Poll;
use futures::FutureExt;
use tokio::sync::oneshot::Receiver;

use crate::error;
use crate::error::DataProcessResult;
use crate::error::Result;
use crate::ringbuf::data_block::DataBlock;
Expand Down Expand Up @@ -44,12 +45,15 @@ pub struct Handle {
}

impl Future for Handle {
type Output = std::result::Result<DataProcessResult, ()>;
type Output = Result<DataProcessResult>;

fn poll(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Self::Output> {
self.rx.poll_unpin(cx).map(|res| res.map_err(|_| ()))
self.rx.poll_unpin(cx).map_err(|e| error::Error::Recv {
source: e,
location: snafu::location!(),
})
}
}

0 comments on commit 4de657c

Please sign in to comment.