Use of async_std::task::sleep instead of tokio::time::sleep in examples (#2912)
* Use of async_std::task::sleep instead of tokio::time::sleep * Make the clock example run on wasm * Add control_focus and eval examples to Cargo.toml * Use web-time on desktop; It just falls back to std on non-wasm platforms --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
1 parent
ffb5c98449
commit
1dfa1b5e7f
9 files changed
+47
-26
No files matched your search
+4
-4
@@ -3,11 +3,11 @@
|
||||
//! use_future won't return a value, analogous to use_effect.
|
||||
//! If you want to return a value from a future, use use_resource instead.
|
||||
|
||||
use async_std::task::sleep;
|
||||
use dioxus::prelude::*;
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
launch_desktop(app);
|
||||
launch(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
@@ -16,7 +16,7 @@ fn app() -> Element {
|
||||
// use_future will run the future
|
||||
use_future(move || async move {
|
||||
loop {
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
sleep(std::time::Duration::from_millis(200)).await;
|
||||
count += 1;
|
||||
}
|
||||
});
|
||||
@@ -24,7 +24,7 @@ fn app() -> Element {
|
||||
// We can also spawn futures from effects, handlers, or other futures
|
||||
use_effect(move || {
|
||||
spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||
sleep(std::time::Duration::from_secs(5)).await;
|
||||
count.set(100);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user