pub struct FutureGroup<F> { /* private fields */ }Available on crate feature
nano-alloc only.Expand description
A growable group of futures which act as a single unit.
§Example
Basic example
use futures_concurrency::future::FutureGroup;
use futures_lite::StreamExt;
use std::future;
let mut group = FutureGroup::new();
group.insert(future::ready(2));
group.insert(future::ready(4));
let mut out = 0;
while let Some(num) = group.next().await {
out += num;
}
assert_eq!(out, 6);Update the group on every iteration
use futures_concurrency::future::FutureGroup;
use lending_stream::prelude::*;
use std::future;
let mut group = FutureGroup::new();
group.insert(future::ready(4));
let mut index = 3;
let mut out = 0;
let mut group = group.lend_mut();
while let Some((group, num)) = group.next().await {
if index != 0 {
group.insert(future::ready(index));
index -= 1;
}
out += num;
}
assert_eq!(out, 10);Implementations§
Source§impl<F> FutureGroup<F>
impl<F> FutureGroup<F>
Sourcepub fn new() -> FutureGroup<F>
Available on crate feature alloc only.
pub fn new() -> FutureGroup<F>
alloc only.Create a new instance of FutureGroup.
§Example
use futures_concurrency::future::FutureGroup;
let group = FutureGroup::new();Sourcepub fn with_capacity(capacity: usize) -> FutureGroup<F>
Available on crate feature alloc only.
pub fn with_capacity(capacity: usize) -> FutureGroup<F>
alloc only.Create a new instance of FutureGroup with a given capacity.
§Example
use futures_concurrency::future::FutureGroup;
let group = FutureGroup::with_capacity(2);Sourcepub fn len(&self) -> usize
Available on crate feature alloc only.
pub fn len(&self) -> usize
alloc only.Return the number of futures currently active in the group.
§Example
use futures_concurrency::future::FutureGroup;
use futures_lite::StreamExt;
use std::future;
let mut group = FutureGroup::with_capacity(2);
assert_eq!(group.len(), 0);
group.insert(future::ready(12));
assert_eq!(group.len(), 1);Sourcepub fn capacity(&self) -> usize
Available on crate feature alloc only.
pub fn capacity(&self) -> usize
alloc only.Return the capacity of the FutureGroup.
§Example
use futures_concurrency::future::FutureGroup;
use futures_lite::stream;
let group = FutureGroup::with_capacity(2);
assert!(group.capacity() >= 2);Sourcepub fn is_empty(&self) -> bool
Available on crate feature alloc only.
pub fn is_empty(&self) -> bool
alloc only.Returns true if there are no futures currently active in the group.
§Example
use futures_concurrency::future::FutureGroup;
use std::future;
let mut group = FutureGroup::with_capacity(2);
assert!(group.is_empty());
group.insert(future::ready(12));
assert!(!group.is_empty());Sourcepub fn remove(&mut self, key: Key) -> bool
Available on crate feature alloc only.
pub fn remove(&mut self, key: Key) -> bool
alloc only.Removes a stream from the group. Returns whether the value was present in the group.
§Example
use futures_concurrency::future::FutureGroup;
use std::future;
let mut group = FutureGroup::new();
let key = group.insert(future::ready(4));
assert_eq!(group.len(), 1);
group.remove(key);
assert_eq!(group.len(), 0);Sourcepub fn contains_key(&mut self, key: Key) -> bool
Available on crate feature alloc only.
pub fn contains_key(&mut self, key: Key) -> bool
alloc only.Returns true if the FutureGroup contains a value for the specified key.
§Example
use futures_concurrency::future::FutureGroup;
use std::future;
let mut group = FutureGroup::new();
let key = group.insert(future::ready(4));
assert!(group.contains_key(key));
group.remove(key);
assert!(!group.contains_key(key));Sourcepub fn reserve(&mut self, additional: usize)
Available on crate feature alloc only.
pub fn reserve(&mut self, additional: usize)
alloc only.Reserves capacity for additional more futures to be inserted.
Does nothing if the capacity is already sufficient.
§Example
use futures_concurrency::future::FutureGroup;
use std::future::Ready;
let mut group: FutureGroup<Ready<usize>> = FutureGroup::with_capacity(0);
assert_eq!(group.capacity(), 0);
group.reserve(10);
assert!(group.capacity() >= 10);
// does nothing if capacity is sufficient
group.reserve(5);
assert!(group.capacity() >= 10);Source§impl<F> FutureGroup<F>where
F: Future,
impl<F> FutureGroup<F>where
F: Future,
Sourcepub fn insert(&mut self, future: F) -> Keywhere
F: Future,
Available on crate feature alloc only.
pub fn insert(&mut self, future: F) -> Keywhere
F: Future,
alloc only.Insert a new future into the group.
§Example
use futures_concurrency::future::FutureGroup;
use std::future;
let mut group = FutureGroup::with_capacity(2);
group.insert(future::ready(12));Sourcepub fn keyed(self) -> Keyed<F>
Available on crate feature alloc only.
pub fn keyed(self) -> Keyed<F>
alloc only.Create a stream which also yields the key of each item.
§Example
use futures_concurrency::future::FutureGroup;
use futures_lite::StreamExt;
use std::future;
let mut group = FutureGroup::new();
group.insert(future::ready(2));
group.insert(future::ready(4));
let mut out = 0;
let mut group = group.keyed();
while let Some((_key, num)) = group.next().await {
out += num;
}
assert_eq!(out, 6);Trait Implementations§
Source§impl<T> Debug for FutureGroup<T>where
T: Debug,
impl<T> Debug for FutureGroup<T>where
T: Debug,
Source§impl<T> Default for FutureGroup<T>
impl<T> Default for FutureGroup<T>
Source§fn default() -> FutureGroup<T>
fn default() -> FutureGroup<T>
Returns the “default value” for a type. Read more
Source§impl<F> Extend<F> for FutureGroup<F>where
F: Future,
impl<F> Extend<F> for FutureGroup<F>where
F: Future,
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = F>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = F>,
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<F> FromIterator<F> for FutureGroup<F>where
F: Future,
impl<F> FromIterator<F> for FutureGroup<F>where
F: Future,
Source§fn from_iter<T>(iter: T) -> FutureGroup<F>where
T: IntoIterator<Item = F>,
fn from_iter<T>(iter: T) -> FutureGroup<F>where
T: IntoIterator<Item = F>,
Creates a value from an iterator. Read more
Source§impl<F> Stream for FutureGroup<F>where
F: Future,
impl<F> Stream for FutureGroup<F>where
F: Future,
Source§fn poll_next(
self: Pin<&mut FutureGroup<F>>,
cx: &mut Context<'_>,
) -> Poll<Option<<FutureGroup<F> as Stream>::Item>>
fn poll_next( self: Pin<&mut FutureGroup<F>>, cx: &mut Context<'_>, ) -> Poll<Option<<FutureGroup<F> as Stream>::Item>>
Attempt to pull out the next value of this stream, registering the
current task for wakeup if the value is not yet available, and returning
None if the stream is exhausted. Read moreimpl<'pin, F> Unpin for FutureGroup<F>where
<PinnedFieldsOfHelperStruct<__FutureGroup<'pin, F>> as PinnedFieldsOfHelperTrait>::Actual: Unpin,
Auto Trait Implementations§
impl<F> Freeze for FutureGroup<F>
impl<F> RefUnwindSafe for FutureGroup<F>where
F: RefUnwindSafe,
impl<F> Send for FutureGroup<F>where
F: Send,
impl<F> Sync for FutureGroup<F>where
F: Sync,
impl<F> UnwindSafe for FutureGroup<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<S> IntoStream for Swhere
S: Stream,
impl<S> IntoStream for Swhere
S: Stream,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<S> StreamExt for S
impl<S> StreamExt for S
Source§fn next(&mut self) -> NextFuture<'_, Self>where
Self: Unpin,
fn next(&mut self) -> NextFuture<'_, Self>where
Self: Unpin,
Retrieves the next item in the stream. Read more
Source§fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>
Retrieves the next item in the stream. Read more
Source§fn count(self) -> CountFuture<Self>where
Self: Sized,
fn count(self) -> CountFuture<Self>where
Self: Sized,
Counts the number of items in the stream. Read more
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Maps items of the stream to new values using a closure. Read more
Source§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
Maps items to streams and then concatenates them. Read more
Source§fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
Maps items of the stream to new values using an async closure. Read more
Source§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
Filters and maps items of the stream using a closure. Read more
Source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
Takes only the first
n items of the stream. Read moreSource§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Source§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
Skips the first
n items of the stream. Read moreSource§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
Source§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
Yields every
stepth item. Read moreSource§fn chain<U>(self, other: U) -> Chain<Self, U>
fn chain<U>(self, other: U) -> Chain<Self, U>
Appends another stream to the end of this one. Read more
Source§fn collect<C>(self) -> CollectFuture<Self, C>
fn collect<C>(self) -> CollectFuture<Self, C>
Collects all items in the stream into a collection. Read more
Source§fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>
Collects all items in the fallible stream into a collection. Read more
Source§fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>
fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>
Partitions items into those for which
predicate is true and those for which it is
false, and then collects them into two collections. Read moreSource§fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>
Accumulates a computation over the stream. Read more
Source§fn try_fold<T, E, F, B>(
&mut self,
init: B,
f: F,
) -> TryFoldFuture<'_, Self, F, B>
fn try_fold<T, E, F, B>( &mut self, init: B, f: F, ) -> TryFoldFuture<'_, Self, F, B>
Accumulates a fallible computation over the stream. Read more
Source§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
Maps items of the stream to new values using a state value and a closure. Read more
Source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Enumerates items, mapping them to
(index, item). Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Calls a closure on each item and passes it on. Read more
Source§fn nth(&mut self, n: usize) -> NthFuture<'_, Self>where
Self: Unpin,
fn nth(&mut self, n: usize) -> NthFuture<'_, Self>where
Self: Unpin,
Gets the
nth item of the stream. Read moreSource§fn last(self) -> LastFuture<Self>where
Self: Sized,
fn last(self) -> LastFuture<Self>where
Self: Sized,
Returns the last item in the stream. Read more
Source§fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>
fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>
Source§fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>
fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>
Source§fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>
fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>
Source§fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>
fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>
Calls a closure on each item of the stream. Read more
Source§fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>
Calls a fallible closure on each item of the stream, stopping on first error. Read more
Source§fn zip<U>(self, other: U) -> Zip<Self, U>
fn zip<U>(self, other: U) -> Zip<Self, U>
Zips up two streams into a single stream of pairs. Read more
Source§fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>
fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>
Collects a stream of pairs into a pair of collections. Read more
Source§fn drain(&mut self) -> Drain<'_, Self>
fn drain(&mut self) -> Drain<'_, Self>
Yields all immediately available values from a stream. Read more
Source§impl<S1> StreamExt for S1where
S1: Stream,
impl<S1> StreamExt for S1where
S1: Stream,
Source§fn merge<T, S2>(
self,
other: S2,
) -> Merge2<T, S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
fn merge<T, S2>(
self,
other: S2,
) -> Merge2<T, S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
Combines two streams into a single stream of all their outputs.
Source§fn chain<T, S2>(self, other: S2) -> Chain2<S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
fn chain<T, S2>(self, other: S2) -> Chain2<S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
Takes two streams and creates a new stream over all in sequence
Source§fn zip<T, S2>(self, other: S2) -> Zip2<S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
fn zip<T, S2>(self, other: S2) -> Zip2<S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
‘Zips up’ multiple streams into a single stream of pairs.
Source§fn co(self) -> FromStream<Self>where
Self: Sized,
fn co(self) -> FromStream<Self>where
Self: Sized,
Available on crate feature
alloc only.Convert into a concurrent stream.
Source§fn wait_until<D>(
self,
deadline: D,
) -> WaitUntil<Self, <D as IntoFuture>::IntoFuture>where
Self: Sized,
D: IntoFuture,
fn wait_until<D>(
self,
deadline: D,
) -> WaitUntil<Self, <D as IntoFuture>::IntoFuture>where
Self: Sized,
D: IntoFuture,
Delay the yielding of items from the stream until the given deadline. Read more