Simplify select with guards
This commit is contained in:
parent
e9456945d9
commit
f3096ac76a
|
@ -44,6 +44,10 @@ where
|
|||
self.1 = opt.is_none();
|
||||
opt
|
||||
}
|
||||
|
||||
fn is_closed(&self) -> bool {
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
struct ReceiverStream<T>(Receiver<T>);
|
||||
|
@ -301,8 +305,6 @@ where
|
|||
|
||||
let mut m = Streamer(m, false);
|
||||
|
||||
let mut stream_finished = false;
|
||||
|
||||
let mut error: Option<Error> = None;
|
||||
let mut provided_error: Option<E> = None;
|
||||
|
||||
|
@ -319,63 +321,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
break 'outer;
|
||||
}
|
||||
|
||||
if stream_finished {
|
||||
while let Some(res) = set.join_next().await {
|
||||
let (name_parts, content) = match res {
|
||||
Ok(Ok(Ok(tup))) => tup,
|
||||
Ok(Ok(Err(e))) => {
|
||||
provided_error = Some(e);
|
||||
continue 'outer;
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
error = Some(e);
|
||||
continue 'outer;
|
||||
}
|
||||
Err(e) => {
|
||||
error = Some(e.into());
|
||||
continue 'outer;
|
||||
}
|
||||
};
|
||||
|
||||
let (l, r) = match count(&content, file_count, field_count, &form) {
|
||||
Ok(tup) => tup,
|
||||
Err(e) => {
|
||||
error = Some(e);
|
||||
continue 'outer;
|
||||
}
|
||||
};
|
||||
|
||||
file_count = l;
|
||||
field_count = r;
|
||||
|
||||
multipart_form.push((name_parts, content));
|
||||
while let Some(_) = set.join_next().await {
|
||||
tracing::trace!("Throwing away joined result");
|
||||
}
|
||||
|
||||
break 'outer;
|
||||
}
|
||||
|
||||
if set.is_empty() {
|
||||
if let Some(res) = m.next().await {
|
||||
match res {
|
||||
Ok(field) => {
|
||||
set.spawn_local(handle_stream_field(field, Rc::clone(&form)));
|
||||
}
|
||||
Err(e) => {
|
||||
error = Some(e.into());
|
||||
continue 'outer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stream_finished = true;
|
||||
continue 'outer;
|
||||
}
|
||||
}
|
||||
|
||||
tokio::select! {
|
||||
opt = m.next() => {
|
||||
opt = m.next(), if !m.is_closed() => {
|
||||
tracing::trace!("Selected stream");
|
||||
if let Some(res) = opt {
|
||||
match res {
|
||||
|
@ -387,12 +341,9 @@ where
|
|||
continue 'outer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stream_finished = true;
|
||||
continue 'outer;
|
||||
}
|
||||
}
|
||||
opt = set.join_next() => {
|
||||
opt = set.join_next(), if !set.is_empty() => {
|
||||
tracing::trace!("Selected set");
|
||||
if let Some(res) = opt {
|
||||
let (name_parts, content) = match res {
|
||||
|
@ -425,6 +376,9 @@ where
|
|||
multipart_form.push((name_parts, content));
|
||||
}
|
||||
}
|
||||
else => {
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue