Stephen Seo
ebf0cb5bb8
This commit is also a stepping-stone towards handling http requests which will require deferred callbacks on Yew Components. By figuring out how to delay callbacks in this commit, it should be easier to figure out how to handle http requests that may require a deferred callback.
16 lines
369 B
Rust
16 lines
369 B
Rust
use js_sys::Promise;
|
|
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen_futures::JsFuture;
|
|
|
|
#[wasm_bindgen(module = "/src/deferred_helper.js")]
|
|
extern "C" {
|
|
fn async_sleep(ms: u32) -> Promise;
|
|
}
|
|
|
|
pub async fn rust_async_sleep(ms: u32) -> Result<(), JsValue> {
|
|
let promise = async_sleep(ms);
|
|
let js_fut = JsFuture::from(promise);
|
|
js_fut.await?;
|
|
Ok(())
|
|
}
|