move to api crate

This commit is contained in:
awtterpip
2023-12-26 14:20:22 -06:00
parent 037f719329
commit ffa9e6d080
26 changed files with 565 additions and 1310 deletions

View File

@@ -0,0 +1,17 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::JsFuture;
use web_sys::js_sys::Promise;
pub trait PromiseRes {
fn resolve<T: From<JsValue>>(self) -> Result<T, JsValue>;
}
impl PromiseRes for Promise {
fn resolve<T: From<JsValue>>(self) -> Result<T, JsValue> {
resolve_promise(self)
}
}
pub fn resolve_promise<T: From<JsValue>>(promise: Promise) -> Result<T, JsValue> {
futures::executor::block_on(async move { JsFuture::from(promise).await.map(Into::into) })
}