EN605.607.81.SP22_ASDM_Project/front_end/src/async_js_helper.rs
Stephen Seo ebf0cb5bb8 Impl async delay on AI choice
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.
2022-03-15 13:16:09 +09:00

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(())
}