use super::{BatchBuilder, StreamBuilder};
use crate::context::Receiver;
use crate::messages::Message;
use std::time::Duration;
pub trait ReceiverExt<T: Message>: Sized {
fn stream(self) -> StreamBuilder<T>;
fn filter<F>(self, predicate: F) -> StreamBuilder<T>
where
F: Fn(&T) -> bool + Send + Sync + 'static;
fn map<F>(self, mapper: F) -> StreamBuilder<T>
where
F: Fn(T) -> T + Send + Sync + 'static;
fn debounce(self, duration: Duration) -> StreamBuilder<T>;
fn throttle(self, duration: Duration) -> StreamBuilder<T>;
fn latest(self) -> StreamBuilder<T>;
fn batch(self, size: usize, timeout: Duration) -> BatchBuilder<T>
where
T: Clone;
fn zip<U>(self, other: Receiver<U>) -> Receiver<(T, U)>
where
U: Message + Send + 'static;
fn window(self, window_duration: Duration) -> Receiver<Vec<T>>
where
T: Clone;
}
impl<T: Message + Send + 'static> ReceiverExt<T> for Receiver<T> {
fn stream(self) -> StreamBuilder<T> {
StreamBuilder::new(self)
}
fn filter<F>(self, predicate: F) -> StreamBuilder<T>
where
F: Fn(&T) -> bool + Send + Sync + 'static,
{
StreamBuilder::new(self).filter(predicate)
}
fn map<F>(self, mapper: F) -> StreamBuilder<T>
where
F: Fn(T) -> T + Send + Sync + 'static,
{
StreamBuilder::new(self).map(mapper)
}
fn debounce(self, duration: Duration) -> StreamBuilder<T> {
StreamBuilder::new(self).debounce(duration)
}
fn throttle(self, duration: Duration) -> StreamBuilder<T> {
StreamBuilder::new(self).throttle(duration)
}
fn latest(self) -> StreamBuilder<T> {
StreamBuilder::new(self).latest()
}
fn batch(self, size: usize, timeout: Duration) -> BatchBuilder<T>
where
T: Clone,
{
BatchBuilder::new(self, size, timeout)
}
fn zip<U>(self, other: Receiver<U>) -> Receiver<(T, U)>
where
U: Message + Send + 'static,
{
StreamBuilder::new(self).zip(other)
}
fn window(self, window_duration: Duration) -> Receiver<Vec<T>>
where
T: Clone,
{
StreamBuilder::new(self).window(window_duration)
}
}