pub struct DurableFuturesUnordered<F> { /* private fields */ }Expand description
A collection of durable futures that yields results as they complete,
similar to futures::stream::FuturesUnordered.
Each future is assigned a stable index when pushed, which is returned
alongside the result from next so you can correlate
outputs with inputs.
§Example
let labels = vec!["fast", "medium", "slow"];
let durations = vec![1, 2, 3];
let mut futures = DurableFuturesUnordered::new();
for secs in &durations {
futures.push(ctx.sleep(Duration::from_secs(*secs)));
}
while let Some((index, result)) = futures.next().await? {
result?;
println!("{} timer done!", labels[index]);
}You can also collect into it from an iterator:
let durations = vec![1, 2, 3];
let mut futures: DurableFuturesUnordered<_> = durations
.iter()
.map(|secs| ctx.sleep(Duration::from_secs(*secs)))
.collect();
while let Some((index, result)) = futures.next().await? {
result?;
}Implementations§
Source§impl<F> DurableFuturesUnordered<F>
impl<F> DurableFuturesUnordered<F>
Source§impl<F: DurableFuture> DurableFuturesUnordered<F>
impl<F: DurableFuture> DurableFuturesUnordered<F>
Sourcepub async fn next(
&mut self,
) -> Result<Option<(usize, F::Output)>, TerminalError>
pub async fn next( &mut self, ) -> Result<Option<(usize, F::Output)>, TerminalError>
Await the next completed future.
Returns Ok(None) if there are no remaining futures.
Returns Err(TerminalError) if the invocation was cancelled.
Returns Ok(Some((index, output))) with the stable index and output
of the next completed future.
Trait Implementations§
Source§impl<F> Default for DurableFuturesUnordered<F>
impl<F> Default for DurableFuturesUnordered<F>
Source§impl<F> FromIterator<F> for DurableFuturesUnordered<F>
impl<F> FromIterator<F> for DurableFuturesUnordered<F>
Source§fn from_iter<I: IntoIterator<Item = F>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = F>>(iter: I) -> Self
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl<F> Freeze for DurableFuturesUnordered<F>
impl<F> RefUnwindSafe for DurableFuturesUnordered<F>where
F: RefUnwindSafe,
impl<F> Send for DurableFuturesUnordered<F>where
F: Send,
impl<F> Sync for DurableFuturesUnordered<F>where
F: Sync,
impl<F> Unpin for DurableFuturesUnordered<F>where
F: Unpin,
impl<F> UnsafeUnpin for DurableFuturesUnordered<F>
impl<F> UnwindSafe for DurableFuturesUnordered<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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more