MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / select_ok

Function select_ok

flow-rs/src/future.rs:15–31  ·  view source on GitHub ↗

https://users.rust-lang.org/t/usage-of-futures-select-ok/46068/10

(futs: impl IntoIterator<Item = F>)

Source from the content-addressed store, hash-verified

13
14// https://users.rust-lang.org/t/usage-of-futures-select-ok/46068/10
15pub(crate) async fn select_ok<F, A, B>(futs: impl IntoIterator<Item = F>) -> Result<A, B>
16where
17 F: Future<Output = Result<A, B>>,
18{
19 let mut futs: FuturesUnordered<F> = futs.into_iter().collect();
20
21 let mut last_error: Option<B> = None;
22 while let Some(next) = futs.next().await {
23 match next {
24 Ok(ok) => return Ok(ok),
25 Err(err) => {
26 last_error = Some(err);
27 }
28 }
29 }
30 Err(last_error.expect("Empty iterator."))
31}
32
33#[cfg(test)]
34mod test {

Callers 1

fetchMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected