mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-17 06:08:26 +00:00
poll tasks in the same order they are queued (#2273)
This commit is contained in:
parent
26c109f661
commit
a012fb57ab
2 changed files with 9 additions and 8 deletions
|
@ -32,6 +32,7 @@ use crate::Task;
|
||||||
use crate::VirtualDom;
|
use crate::VirtualDom;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::collections::VecDeque;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Eq)]
|
#[derive(Debug, Clone, Copy, Eq)]
|
||||||
|
@ -138,7 +139,7 @@ impl VirtualDom {
|
||||||
Some(Work {
|
Some(Work {
|
||||||
scope,
|
scope,
|
||||||
rerun_scope: true,
|
rerun_scope: true,
|
||||||
tasks: Vec::new(),
|
tasks: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
std::cmp::Ordering::Greater => {
|
std::cmp::Ordering::Greater => {
|
||||||
|
@ -165,7 +166,7 @@ impl VirtualDom {
|
||||||
Some(Work {
|
Some(Work {
|
||||||
scope,
|
scope,
|
||||||
rerun_scope: true,
|
rerun_scope: true,
|
||||||
tasks: Vec::new(),
|
tasks: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
(None, Some(_)) => {
|
(None, Some(_)) => {
|
||||||
|
@ -185,27 +186,27 @@ impl VirtualDom {
|
||||||
pub struct Work {
|
pub struct Work {
|
||||||
pub scope: ScopeOrder,
|
pub scope: ScopeOrder,
|
||||||
pub rerun_scope: bool,
|
pub rerun_scope: bool,
|
||||||
pub tasks: Vec<Task>,
|
pub tasks: VecDeque<Task>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq)]
|
#[derive(Debug, Clone, Eq)]
|
||||||
pub(crate) struct DirtyTasks {
|
pub(crate) struct DirtyTasks {
|
||||||
pub order: ScopeOrder,
|
pub order: ScopeOrder,
|
||||||
pub tasks_queued: RefCell<Vec<Task>>,
|
pub tasks_queued: RefCell<VecDeque<Task>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ScopeOrder> for DirtyTasks {
|
impl From<ScopeOrder> for DirtyTasks {
|
||||||
fn from(order: ScopeOrder) -> Self {
|
fn from(order: ScopeOrder) -> Self {
|
||||||
Self {
|
Self {
|
||||||
order,
|
order,
|
||||||
tasks_queued: Vec::new().into(),
|
tasks_queued: VecDeque::new().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DirtyTasks {
|
impl DirtyTasks {
|
||||||
pub fn queue_task(&self, task: Task) {
|
pub fn queue_task(&self, task: Task) {
|
||||||
self.tasks_queued.borrow_mut().push(task);
|
self.tasks_queued.borrow_mut().push_back(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -518,7 +518,7 @@ impl VirtualDom {
|
||||||
while let Some(task) = self.pop_task() {
|
while let Some(task) = self.pop_task() {
|
||||||
// Then poll any tasks that might be pending
|
// Then poll any tasks that might be pending
|
||||||
let mut tasks = task.tasks_queued.into_inner();
|
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);
|
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
|
// 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() {
|
while let Some(task) = self.pop_task() {
|
||||||
// Then poll any tasks that might be pending
|
// Then poll any tasks that might be pending
|
||||||
let mut tasks = task.tasks_queued.into_inner();
|
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) {
|
if self.runtime.task_runs_during_suspense(task) {
|
||||||
let _ = self.runtime.handle_task_wakeup(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
|
// Running that task, may mark a scope higher up as dirty. If it does, return from the function early
|
||||||
|
|
Loading…
Add table
Reference in a new issue