Expand description

Provides an IntervalBuffer that can be used to buffer a stream and emit the values at a regular interval.

This is useful for when you receive streaming data but want to parse it in bulk.

use futures::prelude::*;
use irc::client::prelude::*;
use tokio_interval_buffer::IntervalBuffer;

#[tokio::main]
async fn main() {
    let mut client = Client::from_config(Config {
        nickname: Some(String::from("...")),
        server: Some(String::from("...")),
        channels: vec![String::from("...")],
        ..Default::default()
    })
    .await
    .expect("Could not create an irc client");

    // Take the IRC stream and process all the messages every 10 seconds
    let mut buffered_receiver = IntervalBuffer::<_, _, failure::Error>::new(
        client.stream().unwrap().map_err(|e| e.into()),
        std::time::Duration::from_secs(10),
    );

    while let Some(item) = buffered_receiver.next().await {
        println!("Buffer: {:?}", item);
    }
}

Structs

This buffer takes a stream and an interval, and will emit a VecStream::Item every interval.

Traits

A generic component used for the container for the IntervalBuffer. This can be implemented for any type, and is only implemented for Vec by default.