Skip to main content

Crate async_sleep_aki

Crate async_sleep_aki 

Source
Expand description

It provides simple async_sleep() that work well in both web browsers and native applications. This can be used in the dioxus application.

§Howto use

Just call async_sleep() on the frontend or backend.

async_sleep(100).await;

In dioxus component:

use dioxus::prelude::*;
use async_sleep_aki::delayed_call;

#[component]
fn func() -> Element {
    let mut is_loading = use_signal(|| false);
    use_effect(move ||{
        spawn(delayed_call(2000, async move {
            if *is_loading.read() {
                is_loading.set(false);
            }
        }));
    });
    rsx!{ div{} }
}
use dioxus::prelude::*;
use async_sleep_aki::postponed_call;

#[component]
fn func() -> Element {
    let mut postponed = use_signal(|| postponed_call(10, move || {}));
    let mut is_loading = use_signal(|| false);
    let rsrc = use_resource(move || async move {
        let t = postponed_call(2000, move || {
            if *is_loading.read() {
                is_loading.set(false);
            }
        });
        let _ = postponed.replace(t);
    });
    rsx!{ div{} }
}

§Implementation

If target is wasm32-unknown-unknown, calls gloo_timers::future::sleep(), otherwise calls tokio::time::sleep().

Structs§

PostponedCall

Functions§

async_sleep
Stops processing for delay milliseconds.
delayed_call
Pause processing for delay milliseconds and then call the argument async function.
postponed_call
Create a Task that will call the callback after millis milliseconds.