poll tasks in the same order they are queued (#2273)

This commit is contained in:
Evan Almloff 2024-04-08 20:44:43 -05:00 committed by GitHub
parent 26c109f661
commit a012fb57ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 8 deletions

View file

@ -32,6 +32,7 @@ use crate::Task;
use crate::VirtualDom;
use std::borrow::Borrow;
use std::cell::RefCell;
use std::collections::VecDeque;
use std::hash::Hash;
#[derive(Debug, Clone, Copy, Eq)]
@ -138,7 +139,7 @@ impl VirtualDom {
Some(Work {
scope,
rerun_scope: true,
tasks: Vec::new(),
tasks: Default::default(),
})
}
std::cmp::Ordering::Greater => {
@ -165,7 +166,7 @@ impl VirtualDom {
Some(Work {
scope,
rerun_scope: true,
tasks: Vec::new(),
tasks: Default::default(),
})
}
(None, Some(_)) => {
@ -185,27 +186,27 @@ impl VirtualDom {
pub struct Work {
pub scope: ScopeOrder,
pub rerun_scope: bool,
pub tasks: Vec<Task>,
pub tasks: VecDeque<Task>,
}
#[derive(Debug, Clone, Eq)]
pub(crate) struct DirtyTasks {
pub order: ScopeOrder,
pub tasks_queued: RefCell<Vec<Task>>,
pub tasks_queued: RefCell<VecDeque<Task>>,
}
impl From<ScopeOrder> for DirtyTasks {
fn from(order: ScopeOrder) -> Self {
Self {
order,
tasks_queued: Vec::new().into(),
tasks_queued: VecDeque::new().into(),
}
}
}
impl DirtyTasks {
pub fn queue_task(&self, task: Task) {
self.tasks_queued.borrow_mut().push(task);
self.tasks_queued.borrow_mut().push_back(task);
}
}

View file

@ -518,7 +518,7 @@ impl VirtualDom {
while let Some(task) = self.pop_task() {
// Then poll any tasks that might be pending
let mut tasks = task.tasks_queued.into_inner();
while let Some(task) = tasks.pop() {
while let Some(task) = tasks.pop_front() {
let _ = self.runtime.handle_task_wakeup(task);
// Running that task, may mark a scope higher up as dirty. If it does, return from the function early
@ -702,7 +702,7 @@ impl VirtualDom {
while let Some(task) = self.pop_task() {
// Then poll any tasks that might be pending
let mut tasks = task.tasks_queued.into_inner();
while let Some(task) = tasks.pop() {
while let Some(task) = tasks.pop_front() {
if self.runtime.task_runs_during_suspense(task) {
let _ = self.runtime.handle_task_wakeup(task);
// Running that task, may mark a scope higher up as dirty. If it does, return from the function early