Skip to main content

StreamBatchExt

Trait StreamBatchExt 

Source
pub trait StreamBatchExt:
    Stream
    + Sized
    + Unpin {
    // Provided methods
    fn batched(self, window: Duration) -> Batched<Self> { ... }
    fn batched_with_capacity(
        self,
        window: Duration,
        max_items: usize,
    ) -> Batched<Self> { ... }
}
Expand description

Adds batched to every Stream.

§Example

use finance_query::streaming::{PriceStream, StreamBatchExt};
use futures::StreamExt;
use std::time::Duration;

let mut batches = PriceStream::subscribe(["AAPL", "NVDA", "TSLA"])
    .await?
    .batched(Duration::from_millis(250));

while let Some(batch) = batches.next().await {
    println!("{} updates in this window", batch.len());
}

Provided Methods§

Source

fn batched(self, window: Duration) -> Batched<Self>

Coalesce items arriving within window into one Vec (max 512 items).

Source

fn batched_with_capacity( self, window: Duration, max_items: usize, ) -> Batched<Self>

Same as batched with an explicit per-batch cap.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S> StreamBatchExt for S
where S: Stream + Sized + Unpin,