fix formatting
This commit is contained in:
1 parent
a14e5be7ad
commit
78b9b157dc
7 files changed
+40
-24
No files matched your search
@@ -260,7 +260,9 @@ pub fn after_render(f: impl FnMut() + 'static) {
|
|||||||
pub async fn flush_sync() {
|
pub async fn flush_sync() {
|
||||||
// Wait for the flush lock to be available
|
// Wait for the flush lock to be available
|
||||||
// We release it immediately, so it's impossible for the lock to be held longer than this function
|
// We release it immediately, so it's impossible for the lock to be held longer than this function
|
||||||
Runtime::with(|rt| rt.render_signal.subscribe()).unwrap().await;
|
Runtime::with(|rt| rt.render_signal.subscribe())
|
||||||
|
.unwrap()
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use a hook with a cleanup function
|
/// Use a hook with a cleanup function
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ mod global_context;
|
|||||||
mod mutations;
|
mod mutations;
|
||||||
mod nodes;
|
mod nodes;
|
||||||
mod properties;
|
mod properties;
|
||||||
|
mod render_signal;
|
||||||
mod runtime;
|
mod runtime;
|
||||||
mod scope_arena;
|
mod scope_arena;
|
||||||
mod scope_context;
|
mod scope_context;
|
||||||
mod scopes;
|
mod scopes;
|
||||||
mod tasks;
|
mod tasks;
|
||||||
mod virtual_dom;
|
mod virtual_dom;
|
||||||
mod render_signal;
|
|
||||||
|
|
||||||
pub(crate) mod innerlude {
|
pub(crate) mod innerlude {
|
||||||
pub(crate) use crate::any_props::*;
|
pub(crate) use crate::any_props::*;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::rc::Rc;
|
|
||||||
use std::task::Waker;
|
|
||||||
use std::task::Poll;
|
|
||||||
use std::pin::Pin;
|
|
||||||
use std::future::Future;
|
|
||||||
use std::task::Context;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::future::Future;
|
||||||
|
use std::pin::Pin;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::task::Context;
|
||||||
|
use std::task::Poll;
|
||||||
|
use std::task::Waker;
|
||||||
|
|
||||||
/// A signal is a message that can be sent to all listening tasks at once
|
/// A signal is a message that can be sent to all listening tasks at once
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -26,15 +26,14 @@ impl RenderSignal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a future that resolves when the signal is sent
|
/// Create a future that resolves when the signal is sent
|
||||||
pub fn subscribe(& self) -> RenderSignalFuture {
|
pub fn subscribe(&self) -> RenderSignalFuture {
|
||||||
let inner =Rc::new(RefCell::new(RenderSignalFutureInner {
|
let inner = Rc::new(RefCell::new(RenderSignalFutureInner {
|
||||||
resolved: false,
|
resolved: false,
|
||||||
waker: None,
|
waker: None,
|
||||||
}));
|
}));
|
||||||
self.wakers.borrow_mut().push(inner.clone());
|
self.wakers.borrow_mut().push(inner.clone());
|
||||||
let waker = RenderSignalFuture {
|
println!("RenderSignalFutureInner");
|
||||||
inner
|
let waker = RenderSignalFuture { inner };
|
||||||
};
|
|
||||||
waker
|
waker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
innerlude::{LocalTask, SchedulerMsg},
|
innerlude::{LocalTask, SchedulerMsg},
|
||||||
|
render_signal::RenderSignal,
|
||||||
scope_context::Scope,
|
scope_context::Scope,
|
||||||
scopes::ScopeId,
|
scopes::ScopeId,
|
||||||
Task,
|
Task,
|
||||||
render_signal::RenderSignal
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
cell::{Cell, Ref, RefCell},
|
cell::{Cell, Ref, RefCell},
|
||||||
|
|||||||
@@ -478,7 +478,6 @@ impl VirtualDom {
|
|||||||
match self.rx.next().await.expect("channel should never close") {
|
match self.rx.next().await.expect("channel should never close") {
|
||||||
SchedulerMsg::Immediate(id) => self.mark_dirty(id),
|
SchedulerMsg::Immediate(id) => self.mark_dirty(id),
|
||||||
SchedulerMsg::TaskNotified(id) => {
|
SchedulerMsg::TaskNotified(id) => {
|
||||||
// _ = self.runtime.handle_task_wakeup(id)
|
|
||||||
// Instead of running the task immediately, we insert it into the runtime's task queue.
|
// Instead of running the task immediately, we insert it into the runtime's task queue.
|
||||||
// The task may be marked dirty at the same time as the scope that owns the task is dropped.
|
// The task may be marked dirty at the same time as the scope that owns the task is dropped.
|
||||||
self.mark_task_dirty(id);
|
self.mark_task_dirty(id);
|
||||||
@@ -631,8 +630,8 @@ impl VirtualDom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.scopes_need_rerun = false;
|
|
||||||
self.runtime.render_signal.send();
|
self.runtime.render_signal.send();
|
||||||
|
self.scopes_need_rerun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`Self::render_immediate`] to a vector of mutations for testing purposes
|
/// [`Self::render_immediate`] to a vector of mutations for testing purposes
|
||||||
|
|||||||
@@ -94,14 +94,22 @@ async fn flushing() {
|
|||||||
|
|
||||||
fn app() -> Element {
|
fn app() -> Element {
|
||||||
if generation() > 0 {
|
if generation() > 0 {
|
||||||
|
println!("App");
|
||||||
SEQUENCE.with(|s| s.borrow_mut().push(0));
|
SEQUENCE.with(|s| s.borrow_mut().push(0));
|
||||||
}
|
}
|
||||||
|
use_hook(|| {
|
||||||
|
spawn(async move {
|
||||||
|
needs_update();
|
||||||
|
});
|
||||||
|
});
|
||||||
use_hook(|| {
|
use_hook(|| {
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
flush_sync().await;
|
|
||||||
SEQUENCE.with(|s| s.borrow_mut().push(1));
|
|
||||||
BROADCAST.with(|b| b.1.resubscribe()).recv().await.unwrap();
|
BROADCAST.with(|b| b.1.resubscribe()).recv().await.unwrap();
|
||||||
|
println!("Task 1 recved");
|
||||||
|
flush_sync().await;
|
||||||
|
println!("Task 1");
|
||||||
|
SEQUENCE.with(|s| s.borrow_mut().push(1));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -109,9 +117,11 @@ async fn flushing() {
|
|||||||
use_hook(|| {
|
use_hook(|| {
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
flush_sync().await;
|
|
||||||
SEQUENCE.with(|s| s.borrow_mut().push(2));
|
|
||||||
BROADCAST.with(|b| b.1.resubscribe()).recv().await.unwrap();
|
BROADCAST.with(|b| b.1.resubscribe()).recv().await.unwrap();
|
||||||
|
println!("Task 2 recved");
|
||||||
|
flush_sync().await;
|
||||||
|
println!("Task 2");
|
||||||
|
SEQUENCE.with(|s| s.borrow_mut().push(2));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -126,16 +136,22 @@ async fn flushing() {
|
|||||||
let fut = async {
|
let fut = async {
|
||||||
// Trigger the flush by waiting for work
|
// Trigger the flush by waiting for work
|
||||||
for _ in 0..30 {
|
for _ in 0..30 {
|
||||||
dom.mark_dirty(ScopeId(0));
|
|
||||||
BROADCAST.with(|b| b.0.send(()).unwrap());
|
BROADCAST.with(|b| b.0.send(()).unwrap());
|
||||||
dom.wait_for_work().await;
|
dom.mark_dirty(ScopeId(0));
|
||||||
|
tokio::select! {
|
||||||
|
_ = dom.wait_for_work() => {}
|
||||||
|
_ = tokio::time::sleep(Duration::from_millis(10)) => {}
|
||||||
|
}
|
||||||
dom.render_immediate(&mut dioxus_core::NoOpMutations);
|
dom.render_immediate(&mut dioxus_core::NoOpMutations);
|
||||||
|
println!("Flushed");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = fut => {}
|
_ = fut => {}
|
||||||
_ = tokio::time::sleep(Duration::from_millis(500)) => {}
|
_ = tokio::time::sleep(Duration::from_millis(500)) => {
|
||||||
|
println!("Aborting due to timeout");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SEQUENCE.with(|s| {
|
SEQUENCE.with(|s| {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub fn use_effect(mut callback: impl FnMut() + 'static) {
|
|||||||
loop {
|
loop {
|
||||||
// Run the effect
|
// Run the effect
|
||||||
rc.run_in(&mut callback);
|
rc.run_in(&mut callback);
|
||||||
|
|
||||||
// Wait for context to change
|
// Wait for context to change
|
||||||
rc.changed().await;
|
rc.changed().await;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user