//! Synchronous combinator extensions to futures::TryStream use futures::{TryFuture, TryStream, TryStreamExt}; use super::automatic_width; use crate::Result; /// Concurrency extensions to augment futures::TryStreamExt. broad_ combinators /// produce out-of-order pub trait TryBroadbandExt where Self: TryStream> + Send + Sized, { fn broadn_and_then( self, n: N, f: F, ) -> impl TryStream> + Send where N: Into>, F: Fn(Self::Ok) -> Fut + Send, Fut: TryFuture> + Send; fn broad_and_then( self, f: F, ) -> impl TryStream> + Send where F: Fn(Self::Ok) -> Fut + Send, Fut: TryFuture> + Send, { self.broadn_and_then(None, f) } } impl TryBroadbandExt for S where S: TryStream> + Send + Sized, { fn broadn_and_then( self, n: N, f: F, ) -> impl TryStream> + Send where N: Into>, F: Fn(Self::Ok) -> Fut + Send, Fut: TryFuture> + Send, { self.map_ok(f) .try_buffer_unordered(n.into().unwrap_or_else(automatic_width)) } }