Skip to content

Commit 66a1798

Browse files
committed
Place a buffer over each sink of a demux to avoid serial message sending
1 parent 837f410 commit 66a1798

File tree

1 file changed

+9
-6
lines changed
  • hydroflow_cli_integration/src

1 file changed

+9
-6
lines changed

hydroflow_cli_integration/src/lib.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
use bytes::{Bytes, BytesMut};
1313
use serde::{Deserialize, Serialize};
1414

15-
use futures::{ready, stream, Sink, Stream};
15+
use futures::{ready, stream, Sink, Stream, SinkExt, sink::Buffer};
1616

1717
use async_recursion::async_recursion;
1818
use async_trait::async_trait;
@@ -395,9 +395,12 @@ impl ConnectedSink for ConnectedBidi {
395395
}
396396
}
397397

398-
pub struct ConnectedDemux<T: ConnectedSink> {
398+
pub type BufferedDrain<S, I> = DemuxDrain<I, Buffer<S, I>>;
399+
400+
pub struct ConnectedDemux<T: ConnectedSink>
401+
where <T as ConnectedSink>::Input: Sync {
399402
pub keys: Vec<u32>,
400-
sink: Option<DemuxDrain<T::Input, T::Sink>>,
403+
sink: Option<BufferedDrain<T::Sink, T::Input>>,
401404
}
402405

403406
#[pin_project]
@@ -460,7 +463,7 @@ where
460463
for (id, pipe) in demux {
461464
connected_demux.insert(
462465
id,
463-
Box::pin(T::from_defn(ServerOrBound::Server(pipe)).await.into_sink()),
466+
Box::pin(T::from_defn(ServerOrBound::Server(pipe)).await.into_sink().buffer(1024)),
464467
);
465468
}
466469

@@ -481,7 +484,7 @@ where
481484
for (id, bound) in demux {
482485
connected_demux.insert(
483486
id,
484-
Box::pin(T::from_defn(ServerOrBound::Bound(bound)).await.into_sink()),
487+
Box::pin(T::from_defn(ServerOrBound::Bound(bound)).await.into_sink().buffer(1024)),
485488
);
486489
}
487490

@@ -505,7 +508,7 @@ where
505508
<T as ConnectedSink>::Input: 'static + Sync,
506509
{
507510
type Input = (u32, T::Input);
508-
type Sink = DemuxDrain<T::Input, T::Sink>;
511+
type Sink = BufferedDrain<T::Sink, T::Input>;
509512

510513
fn into_sink(mut self) -> Self::Sink {
511514
self.sink.take().unwrap()

0 commit comments

Comments
 (0)