2024-01-08 19:25:20 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
use futures_util::{future, stream, Stream, StreamExt};
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
2024-01-16 17:45:02 +00:00
|
|
|
launch_desktop(app);
|
2024-01-08 19:25:20 +00:00
|
|
|
}
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-16 07:24:59 +00:00
|
|
|
let mut count = use_signal(|| 10);
|
2024-01-08 19:25:20 +00:00
|
|
|
|
2024-01-16 01:04:39 +00:00
|
|
|
use_future(|| async move {
|
2024-01-08 19:25:20 +00:00
|
|
|
let mut stream = some_stream();
|
|
|
|
|
|
|
|
while let Some(second) = stream.next().await {
|
|
|
|
count.set(second);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {
|
2024-01-08 19:25:20 +00:00
|
|
|
h1 { "High-Five counter: {count}" }
|
2024-01-14 05:12:21 +00:00
|
|
|
}
|
2024-01-08 19:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn some_stream() -> std::pin::Pin<Box<dyn Stream<Item = i32>>> {
|
|
|
|
Box::pin(
|
|
|
|
stream::once(future::ready(0)).chain(stream::iter(1..).then(|second| async move {
|
|
|
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
|
|
|
second
|
|
|
|
})),
|
|
|
|
)
|
|
|
|
}
|