在 `wasm32-unknown-unknown` 上实现 Send for Context 到 WASM
fn load_file(
dialog: AsyncFileDialog,
import_type: ImportType,
state: Arc<Mutex>,
ctx: Context,
) {
*state.lock().unwrap() = FileLoadState::Reading { progress: None };
let process = async move {
let data = dialog.pick_file().await;
let Some(data) = data else {
*state.lock().unwrap() = FileLoadState::Idle;
return;
}
*state.lock().unwrap() = FileLoadState::Processing { progress: None };
let data = data.read().await;
rayon::spawn(move || {
let commands = generate_commands(&data, import_type).map_err(|e| e.to_string());
*state.lock().unwrap() = FileLoadState::Done(commands);
ctx.request_repaint();
});
}
#[cfg(target_arch = "wasm32")]
{
wasm_bindgen_futures::spawn_local(process);
}
#[cfg(not(target_arch = "wasm32"))]
{
let _ = std::thread::spawn(move || pollster::block_on(process));
}
}
I got this error that basically says I can't send Context to another thread in wasm32-unknown-unknown. I thought it would implement send in this case. In this case I can fix it by using futures_channel and awaiting the thread in the async block, but I want to know why Context doesn't impl Send.
内容来源: emilk/egui