mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-16 21:58:25 +00:00
wip: use signal for clock
This commit is contained in:
parent
3733ce7332
commit
24b6874e97
1 changed files with 8 additions and 12 deletions
|
@ -3,29 +3,25 @@
|
||||||
//! The example from the README.md.
|
//! The example from the README.md.
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_signals::{use_init_signal_rt, use_signal};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dioxus_desktop::launch(app);
|
dioxus_desktop::launch(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
let count = use_ref(cx, || 0);
|
use_init_signal_rt(cx);
|
||||||
|
|
||||||
let ct = count.to_owned();
|
let mut count = use_signal(cx, || 0);
|
||||||
use_coroutine(cx, |_: UnboundedReceiver<()>| async move {
|
|
||||||
|
use_future!(cx, || async move {
|
||||||
loop {
|
loop {
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||||
|
count += 1;
|
||||||
*ct.write() += 1;
|
println!("current: {}", count);
|
||||||
|
|
||||||
let current = *ct.read();
|
|
||||||
|
|
||||||
println!("current: {}", current);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let count = count.read();
|
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div { "High-Five counter: {count}" }
|
div { "High-Five counter: {count}" }
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue