Crates.io | tokio_interval_buffer |
lib.rs | tokio_interval_buffer |
version | 0.2.0 |
source | src |
created_at | 2019-02-16 15:01:25.198935 |
updated_at | 2022-04-03 19:10:09.937675 |
description | Easy enum wrapper that implements all traits that the wrapped objects implement |
homepage | https://github.com/trangar/tokio_interval_buffer |
repository | https://github.com/trangar/tokio_interval_buffer |
max_upload_size | |
id | 115176 |
size | 11,719 |
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.
extern crate irc;
extern crate failure;
extern crate tokio_interval_buffer;
extern crate futures;
extern crate tokio;
use irc::client::prelude::*;
use tokio_interval_buffer::IntervalBuffer;
fn main() {
tokio::run(futures::future::lazy(|| {
let client = IrcClient::from_config(Config {
nickname: Some(String::from("...")),
server: Some(String::from("...")),
channels: Some(vec![String::from("...")]),
..Default::default()
})
.expect("Could not create an irc client");
// Take the IRC stream and process all the messages every 10 seconds
let buffered_receiver = IntervalBuffer::<_, _, failure::Error>::new(
client
.stream()
.map_err(|e| failure::format_err!("Client stream error: {:?}", e)),
std::time::Duration::from_secs(10),
);
buffered_receiver
.for_each(|b| {
println!("Buffer: {:?}", b);
Ok(())
})
.map_err(|e| {
println!("Buffered receiver error: {:?}", e);
})
}));
}