1
0

async.rs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //! Example: README.md showcase
  2. //!
  3. //! The example from the README.md
  4. use std::{pin::Pin, time::Duration};
  5. use dioxus::prelude::*;
  6. use futures::Future;
  7. fn main() {
  8. env_logger::init();
  9. log::info!("hello world");
  10. dioxus::desktop::launch(App, |c| c).expect("faield to launch");
  11. }
  12. #[derive(serde::Deserialize)]
  13. struct DogApi {
  14. message: String,
  15. }
  16. const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random";
  17. static App: FC<()> = |cx| {
  18. let mut count = use_state(cx, || 0);
  19. let mut fut = Box::pin(async {
  20. let mut tick: i32 = 0;
  21. loop {
  22. async_std::task::sleep(Duration::from_millis(250)).await;
  23. log::debug!("ticking forward... {}", tick);
  24. tick += 1;
  25. // match surf::get(ENDPOINT).recv_json::<DogApi>().await {
  26. // Ok(_) => (),
  27. // Err(_) => (),
  28. // }
  29. }
  30. });
  31. cx.submit_task(fut);
  32. cx.render(rsx! {
  33. div {
  34. h1 {"it's working somewhat properly"}
  35. }
  36. })
  37. };