pub struct RealtimePipeline<T: Send + 'static, O: Send + 'static> { /* private fields */ }Expand description
Real-time streaming pipeline with backpressure.
Wraps any StreamingPipeline with a bounded input queue and drives it
from a background worker thread. Flow control works as follows:
sendblocks the caller when the queue is full — the producer is naturally throttled without any explicit rate-limiter code.try_sendnever blocks; it drops the item and incrementsRealtimeMetrics::items_droppedwhen the queue is full.- Call
finishto close the input, drain remaining items, join the worker, and retrieve the pipeline’s final output. - Dropping the pipeline without calling
finishis safe: the channel is closed and the worker is joined in theDropimpl (result discarded).
§Example
use threecrate_algorithms::streaming::{
StreamingCollector, BackpressureConfig, RealtimePipeline,
};
use threecrate_core::Point3f;
let config = BackpressureConfig { max_queue_depth: 64, chunk_size: 16, ..Default::default() };
let rt = RealtimePipeline::new(StreamingCollector::new(), config);
for i in 0..50_u32 {
rt.send(Point3f::new(i as f32, 0.0, 0.0)).unwrap();
}
let cloud = rt.finish().unwrap();
assert_eq!(cloud.len(), 50);Implementations§
Source§impl<T: Send + 'static, O: Send + 'static> RealtimePipeline<T, O>
impl<T: Send + 'static, O: Send + 'static> RealtimePipeline<T, O>
Sourcepub fn new<P>(pipeline: P, config: BackpressureConfig) -> Selfwhere
P: StreamingPipeline<T, Output = O> + Send + 'static,
pub fn new<P>(pipeline: P, config: BackpressureConfig) -> Selfwhere
P: StreamingPipeline<T, Output = O> + Send + 'static,
Create a new real-time pipeline backed by pipeline.
The worker thread starts immediately and is ready to receive items.
Sourcepub fn send(&self, item: T) -> Result<()>
pub fn send(&self, item: T) -> Result<()>
Send an item, blocking until queue space is available (backpressure).
Returns Err if the worker thread has unexpectedly terminated.
Sourcepub fn try_send(&self, item: T) -> Result<bool>
pub fn try_send(&self, item: T) -> Result<bool>
Try to send without blocking.
Returns Ok(true) when the item was queued, Ok(false) when the queue
was full and the item was dropped (counted in
RealtimeMetrics::items_dropped). Returns Err if the worker has
terminated unexpectedly.
Sourcepub fn metrics(&self) -> RealtimeMetrics
pub fn metrics(&self) -> RealtimeMetrics
Snapshot current pipeline metrics.
Trait Implementations§
Auto Trait Implementations§
impl<T, O> Freeze for RealtimePipeline<T, O>
impl<T, O> !RefUnwindSafe for RealtimePipeline<T, O>
impl<T, O> Send for RealtimePipeline<T, O>
impl<T, O> Sync for RealtimePipeline<T, O>
impl<T, O> Unpin for RealtimePipeline<T, O>
impl<T, O> UnsafeUnpin for RealtimePipeline<T, O>
impl<T, O> !UnwindSafe for RealtimePipeline<T, O>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.