wip: use signal for clock

This commit is contained in:
Jonathan Kelley 2023-01-04 12:59:35 -05:00
parent 3733ce7332
commit 24b6874e97

View file

@ -3,29 +3,25 @@
//! The example from the README.md.
use dioxus::prelude::*;
use dioxus_signals::{use_init_signal_rt, use_signal};
fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let count = use_ref(cx, || 0);
use_init_signal_rt(cx);
let ct = count.to_owned();
use_coroutine(cx, |_: UnboundedReceiver<()>| async move {
let mut count = use_signal(cx, || 0);
use_future!(cx, || async move {
loop {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
*ct.write() += 1;
let current = *ct.read();
println!("current: {}", current);
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
count += 1;
println!("current: {}", count);
}
});
let count = count.read();
cx.render(rsx! {
div { "High-Five counter: {count}" }
})