fix(multiplexer): Use buffers that own the inner channel (#113)
This commit is contained in:
parent
c6c5f7b1c0
commit
8b54dbeeac
7 changed files with 45 additions and 32 deletions
|
|
@ -46,13 +46,13 @@ where
|
|||
}
|
||||
|
||||
/// A channel abstraction to hide the complexity of partial payloads
|
||||
pub struct ChannelBuffer<'c, C: Channel> {
|
||||
channel: &'c mut C,
|
||||
pub struct ChannelBuffer<C: Channel> {
|
||||
channel: C,
|
||||
temp: Vec<u8>,
|
||||
}
|
||||
|
||||
impl<'c, C: Channel> ChannelBuffer<'c, C> {
|
||||
pub fn new(channel: &'c mut C) -> Self {
|
||||
impl<C: Channel> ChannelBuffer<C> {
|
||||
pub fn new(channel: C) -> Self {
|
||||
Self {
|
||||
channel,
|
||||
temp: Vec::new(),
|
||||
|
|
@ -105,4 +105,14 @@ impl<'c, C: Channel> ChannelBuffer<'c, C> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unwrap(self) -> C {
|
||||
self.channel
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: Channel> From<C> for ChannelBuffer<C> {
|
||||
fn from(channel: C) -> Self {
|
||||
ChannelBuffer::new(channel)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
use crate::{agents, demux, mux, Payload};
|
||||
use crate::{
|
||||
agents::{self, ChannelBuffer},
|
||||
demux, mux, Payload,
|
||||
};
|
||||
|
||||
use std::{
|
||||
sync::{
|
||||
|
|
@ -103,6 +106,8 @@ impl demux::Demuxer<StdEgress> {
|
|||
|
||||
pub type StdChannel = (Sender<Payload>, Receiver<Payload>);
|
||||
|
||||
pub type StdChannelBuffer = ChannelBuffer<StdChannel>;
|
||||
|
||||
impl agents::Channel for StdChannel {
|
||||
fn enqueue_chunk(&mut self, payload: Payload) -> Result<(), agents::ChannelError> {
|
||||
match self.0.send(payload) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue