I know that wasm doesn't have blocking so how would I do the equivalent. Or is there a different tool to use? I'm new to this so it could also be that my approach is completely off. I'm using wasm-pack with a web target to compile.
fn fetch_definitions(def_dir: &str, spelling: &str) -> Result<WordDefs, Error> {
let path = format!("{def_dir}/{spelling}_definitions.json");
let r = wasm_bindgen_futures::spawn_local(async move {
let response: WordDefs = gloo_net::http::Request::get(path.as_str())
.send()
.await
.unwrap()
.json()
.await
.unwrap();
});
// what I would normally do to get a value from a future
// let value = executor::block_on(r);
Err(Error::CouldNotLookUpWord)
}
As I know I have to use wasm_bindgen_futures for the async block and spawn_local has output=(), I can figure out how to get around this.