pub async fn sleep(delay: i32) {
let mut cb = |resolve: js_sys::Function, reject: js_sys::Function| {
web_sys::window()
.unwrap()
.set_timeout_with_callback_and_timeout_and_arguments_0(&resolve, delay);};
let p = js_sys::Promise::new(&mut cb);
wasm_bindgen_futures::JsFuture::from(p).await.unwrap();}
compiles and appears to work.
I have no idea how safe/unsafe this is to use. Insights anyone? [In particular, I lack the understanding of what preconditions the JS / Rust async 'border' have of each other, so I have no idea if I'm breaking any assumptions here.]