core: cleanup tasks polling fn

This commit is contained in:
Yin Jifeng committed 2022-06-13 18:43:36 +08:00
1 parent c97f051bbd
commit 7576426c93
1 file changed
+4 -21
+4 -21
View File
@@ -337,29 +337,12 @@ impl VirtualDom {
let scopes = &mut self.scopes;
let task_poll = poll_fn(|cx| {
//
let mut any_pending = false;
let mut tasks = scopes.tasks.tasks.borrow_mut();
let mut to_remove = vec![];
tasks.retain(|_, task| task.as_mut().poll(cx).is_pending());
// this would be better served by retain
for (id, task) in tasks.iter_mut() {
if task.as_mut().poll(cx).is_ready() {
to_remove.push(*id);
} else {
any_pending = true;
}
}
for id in to_remove {
tasks.remove(&id);
}
// Resolve the future if any singular task is ready
match any_pending {
true => Poll::Pending,
false => Poll::Ready(()),
match tasks.is_empty() {
true => Poll::Ready(()),
false => Poll::Pending,
}
});