Implement Send for Context on WASM on `wasm32-unknown-unknown`
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
(Originally posted on )
```
`hashbrown::raw::RawTable<(ViewportId, egui::context::ViewportState)>` cannot be sent between threads safely
within `egui::context::ContextImpl`, the trait `Send` is not implemented for `hashbrown::raw::RawTable<(ViewportId, egui::context::ViewportState)>`
required for `lock_api::rwlock::RwLock` to implement `Sync`
required for `Arc>` to implement `Send`
the full name for the type has been written to '/home/jeremyg/Code/Paiagram/target/wasm32-unknown-unknown/debug/build/paiagram/3dd480a25331672d/out/paiagram-3dd480a25331672d.long-type-15969912598606154758.txt'
consider using `--verbose` to print the full type name to the console
```
```rust
fn load_file(
dialog: AsyncFileDialog,
import_type: ImportType,
state: Arc>,
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.
Contributor guide
Research direction
Start with egui::context::ContextImpl and its RawTable member, then compare the wasm32-unknown-unknown and native synchronization assumptions shown by the compiler error. Trace the load_file entry point and its rayon::spawn usage, and run a wasm32-unknown-unknown build to verify whether the intended Send behavior is supported without breaking native targets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100