Replies: 6 comments 1 reply
-
There is |
Beta Was this translation helpful? Give feedback.
-
AFAIK the wasm_bindgen_futures::spawn_local function only supports |
Beta Was this translation helpful? Give feedback.
-
That isn't the problem, exporting an async function uses What does |
Beta Was this translation helpful? Give feedback.
-
pub async fn get_link_matches(note_to_check: &Note, target_note_candidates: &Vec<Note>) -> Result<JsValue, JsValue> {
let link_matches: Vec<LinkMatch> =
target_note_candidates
.iter()
.filter_map(|target_note: &Note| {
if !&target_note.title().eq(¬e_to_check.title()) {
let link_matcher_result = LinkMatcherResult::new(
¬e_to_check,
target_note
);
let link_matches: Vec<LinkMatch> = link_matcher_result.into();
return Some(link_matches);
}
None
})
.flatten()
.fold(Vec::new(), |mut merged_link_matches, mut link_match| {
let index = merged_link_matches.iter()
.position(|m: &LinkMatch| m.position().is_equal_to(&link_match.position()));
if let Some(index) = index {
// merge it into the existing match, if the position is the same
merged_link_matches[index].merge_link_match_target_candidates(link_match);
} else {
// otherwise push a new match
merged_link_matches.push(link_match);
}
merged_link_matches
});
if !link_matches.is_empty() {
let js_note_matching_result: JsValue = NoteMatchingResult::new(
note_to_check.clone(),
link_matches
).into();
Ok(js_note_matching_result)
} else {
Err(js_sys::Error::new("idk").into())
}
} |
Beta Was this translation helpful? Give feedback.
-
Yep, that's the problem - making a function See https://github.com/mdn/dom-examples/blob/master/web-workers/simple-web-worker/main.js for a basic example of how they work; you'd have to set up a system to resolve the right If you need to share stuff with the main thread, you could use multithreaded WebAssembly (example). It requires nightly Rust and a bit of extra setup to use though. |
Beta Was this translation helpful? Give feedback.
-
@AlexW00 Did you ever figure out how to get a result from a future on wasm? |
Beta Was this translation helpful? Give feedback.
-
Describe the Bug
My async Rust function, which is exported to JS using wasm_bindgen, blocks the main thread when called.
Steps to Reproduce
This is how the async function gets called:
This is its definition:
Expected Behavior
I expect the async code to not block the main thread.
Actual Behavior
The whole UI (electron) freezes, as if the code was not async.
Additional Context
Part of an electron project.
Beta Was this translation helpful? Give feedback.
All reactions