use async_std::future::Future;
use async_std::task::{Context, Poll};
use std::pin::Pin;
use crate::FromParallelStream;
pub use for_each::ForEach;
pub use map::Map;
pub use next::NextFuture;
pub use take::Take;
mod for_each;
mod map;
mod next;
mod take;
pub trait ParallelStream: Sized + Send + Sync + Unpin + 'static {
type Item: Send;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
fn limit(self, limit: impl Into<Option<usize>>) -> Self;
fn get_limit(&self) -> Option<usize>;
fn map<F, T, Fut>(self, f: F) -> Map<T>
where
F: FnMut(Self::Item) -> Fut + Send + Sync + Copy + 'static,
T: Send + 'static,
Fut: Future<Output = T> + Send,
{
Map::new(self, f)
}
fn next(&mut self) -> NextFuture<'_, Self> {
NextFuture::new(self)
}
fn take(self, n: usize) -> Take<Self>
where
Self: Sized,
{
Take::new(self, n)
}
fn for_each<F, Fut>(self, f: F) -> ForEach
where
F: FnMut(Self::Item) -> Fut + Send + Sync + Copy + 'static,
Fut: Future<Output = ()> + Send,
{
ForEach::new(self, f)
}
fn collect<'a, B>(self) -> Pin<Box<dyn Future<Output = B> + 'a + Send>>
where
Self: Sized + 'a,
B: FromParallelStream<Self::Item>,
{
FromParallelStream::from_par_stream(self)
}
}