2024-01-08 11:25:20 -08:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
use futures_util::{future, stream, Stream, StreamExt};
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
2024-01-16 11:45:02 -06:00
|
|
|
launch_desktop(app);
|
2024-01-08 11:25:20 -08:00
|
|
|
}
|
|
|
|
|
2024-01-13 20:51:37 -08:00
|
|
|
fn app() -> Element {
|
2024-01-15 23:24:59 -08:00
|
|
|
let mut count = use_signal(|| 10);
|
2024-01-08 11:25:20 -08:00
|
|
|
|
2024-01-15 17:04:39 -08:00
|
|
|
use_future(|| async move {
|
2024-01-08 11:25:20 -08:00
|
|
|
let mut stream = some_stream();
|
|
|
|
|
|
|
|
while let Some(second) = stream.next().await {
|
|
|
|
count.set(second);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-16 13:18:46 -06:00
|
|
|
rsx! {
|
2024-01-08 11:25:20 -08:00
|
|
|
h1 { "High-Five counter: {count}" }
|
2024-01-13 21:12:21 -08:00
|
|
|
}
|
2024-01-08 11:25:20 -08: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
|
|
|
|
})),
|
|
|
|
)
|
|
|
|
}
|