wip: refactor to fix some ownership quirks
This commit is contained in:
1 parent
3bf19d8106
commit
05e960b6b0
16 files changed
+549
-535
No files matched your search
@@ -1,7 +1,7 @@
|
||||
//! tests to prove that the iterative implementation works
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{arena::SharedResources, diff::DiffMachine, prelude::*, DomEdit, Mutations};
|
||||
use dioxus::{arena::Scheduler, diff::DiffMachine, prelude::*, DomEdit, Mutations};
|
||||
mod test_logging;
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use bumpalo::Bump;
|
||||
|
||||
use dioxus::{
|
||||
arena::SharedResources, diff::DiffMachine, prelude::*, DiffInstruction, DomEdit, MountType,
|
||||
arena::Scheduler, diff::DiffMachine, prelude::*, DiffInstruction, DomEdit, MountType,
|
||||
};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
@@ -17,13 +17,13 @@ const IS_LOGGING_ENABLED: bool = false;
|
||||
|
||||
struct TestDom {
|
||||
bump: Bump,
|
||||
resources: SharedResources,
|
||||
resources: Scheduler,
|
||||
}
|
||||
impl TestDom {
|
||||
fn new() -> TestDom {
|
||||
test_logging::set_up_logging(IS_LOGGING_ENABLED);
|
||||
let bump = Bump::new();
|
||||
let resources = SharedResources::new();
|
||||
let resources = Scheduler::new();
|
||||
TestDom { bump, resources }
|
||||
}
|
||||
fn new_factory<'a>(&'a self) -> NodeFactory<'a> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use bumpalo::Bump;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{arena::SharedResources, diff::DiffMachine, prelude::*, DomEdit};
|
||||
use dioxus::{arena::Scheduler, diff::DiffMachine, prelude::*, DomEdit};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
|
||||
@@ -17,11 +17,6 @@ async fn event_queue_works() {
|
||||
let edits = dom.rebuild();
|
||||
|
||||
async_std::task::spawn_local(async move {
|
||||
match dom.run_unbounded().await {
|
||||
Err(_) => todo!(),
|
||||
Ok(mutations) => {
|
||||
//
|
||||
}
|
||||
}
|
||||
let mutations = dom.run_unbounded().await;
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{arena::SharedResources, diff::DiffMachine, prelude::*, DomEdit};
|
||||
use dioxus::{arena::Scheduler, diff::DiffMachine, prelude::*, DomEdit};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
use futures_util::StreamExt;
|
||||
|
||||
/*
|
||||
furtures_channel provides us some batching simply due to how Rust's async works.
|
||||
|
||||
Any hook that uses schedule_update is simply deferring to unbounded_send. Multiple
|
||||
unbounded_sends can be linked together in succession provided there isn't an "await"
|
||||
between them. Our internal batching mechanism simply waits for the "schedule_update"
|
||||
to fire and then pulls any messages off the unbounded_send queue.
|
||||
|
||||
Additionally, due to how our "time slicing" works we'll always come back and check
|
||||
in for new work if the deadline hasn't expired. On average, our deadline should be
|
||||
about 10ms, which is way more than enough for diffing/creating to happen.
|
||||
*/
|
||||
#[async_std::test]
|
||||
async fn batch() {
|
||||
let (sender, mut recver) = futures_channel::mpsc::unbounded::<i32>();
|
||||
|
||||
let handle = async_std::task::spawn(async move {
|
||||
let msg = recver.next().await;
|
||||
while let Ok(msg) = recver.try_next() {
|
||||
println!("{:#?}", msg);
|
||||
}
|
||||
let msg = recver.next().await;
|
||||
while let Ok(msg) = recver.try_next() {
|
||||
println!("{:#?}", msg);
|
||||
}
|
||||
});
|
||||
|
||||
sender.unbounded_send(1).unwrap();
|
||||
sender.unbounded_send(2).unwrap();
|
||||
sender.unbounded_send(3).unwrap();
|
||||
sender.unbounded_send(4).unwrap();
|
||||
|
||||
async_std::task::sleep(std::time::Duration::from_millis(100)).await;
|
||||
|
||||
sender.unbounded_send(5).unwrap();
|
||||
sender.unbounded_send(6).unwrap();
|
||||
sender.unbounded_send(7).unwrap();
|
||||
sender.unbounded_send(8).unwrap();
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
//! This means you can actually call it synchronously if you want.
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{arena::SharedResources, diff::DiffMachine, prelude::*, scope::Scope};
|
||||
use dioxus::{arena::Scheduler, diff::DiffMachine, prelude::*, scope::Scope};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
use futures_util::FutureExt;
|
||||
|
||||
Reference in new issue
Block a user