mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-11-15 04:25:19 +00:00
refactor channel receiver
This commit is contained in:
parent
84a3cc3cbb
commit
d3d0a3cd9f
@ -3,7 +3,6 @@ use crate::metrics::unbounded_channel;
|
||||
use metrics::{Counter, CounterUsize};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::mpsc::error::TryRecvError;
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::time::timeout;
|
||||
|
||||
@ -31,7 +30,7 @@ impl<N, Req, Res> Channel<N, Req, Res> {
|
||||
chan: sender,
|
||||
metrics_timeout,
|
||||
},
|
||||
Receiver { chan: receiver },
|
||||
receiver,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -74,19 +73,7 @@ impl<N, Req, Res> Sender<N, Req, Res> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Receiver<N, Req, Res> {
|
||||
chan: crate::metrics::Receiver<Message<N, Req, Res>>,
|
||||
}
|
||||
|
||||
impl<N, Req, Res> Receiver<N, Req, Res> {
|
||||
pub async fn recv(&mut self) -> Option<Message<N, Req, Res>> {
|
||||
self.chan.recv().await
|
||||
}
|
||||
|
||||
pub fn try_recv(&mut self) -> Result<Message<N, Req, Res>, TryRecvError> {
|
||||
self.chan.try_recv()
|
||||
}
|
||||
}
|
||||
pub type Receiver<N, Req, Res> = crate::metrics::Receiver<Message<N, Req, Res>>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
Loading…
Reference in New Issue
Block a user