fix multithread
This commit is contained in:
+7
-28
@@ -31,30 +31,6 @@ impl MonotonicClock for CustomTimeProvider {
|
||||
|
||||
define_time_provider!(CustomTimeProvider);
|
||||
|
||||
/// Returns the preferred WebGPU/WebGL backend, selected with
|
||||
/// `?backend=webgpu` / `?backend=webgl` in the page URL.
|
||||
#[cfg(target_family = "wasm")]
|
||||
fn requested_backend() -> gpui_platform::WebBackendPreference {
|
||||
let search = web_sys::window()
|
||||
.and_then(|window| window.location().search().ok())
|
||||
.unwrap_or_default();
|
||||
if search
|
||||
.trim_start_matches('?')
|
||||
.split('&')
|
||||
.any(|parameter| parameter == "backend=webgpu")
|
||||
{
|
||||
gpui_platform::WebBackendPreference::WebGpu
|
||||
} else if search
|
||||
.trim_start_matches('?')
|
||||
.split('&')
|
||||
.any(|parameter| parameter == "backend=webgl")
|
||||
{
|
||||
gpui_platform::WebBackendPreference::WebGl
|
||||
} else {
|
||||
gpui_platform::WebBackendPreference::Auto
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static APPLICATION: RefCell<Option<ApplicationHandle>> = const { RefCell::new(None) };
|
||||
}
|
||||
@@ -120,10 +96,13 @@ pub async fn run() -> Result<(), JsValue> {
|
||||
// immediately instead of waiting for a repaint.
|
||||
assets.preload().await;
|
||||
|
||||
// Multithreaded web: background work (image decoding, network
|
||||
// fetches, CPU-heavy tasks) runs on real worker threads instead of
|
||||
// the main thread, so the UI stays responsive.
|
||||
gpui_platform::application_with_web_backend(requested_backend()).with_assets(assets)
|
||||
// NOTE: the multithreaded web backend (application_with_web_backend)
|
||||
// cannot host this app's backend. gpui's wasm background workers
|
||||
// block on `Atomics.wait` while idle, freezing their JS event loop,
|
||||
// so `spawn_local`-driven tasks (nostr-sdk's client actor, the
|
||||
// WebSocket transport) and fetch promises never make progress on a
|
||||
// worker thread. Everything must run on the main thread.
|
||||
gpui_platform::single_threaded_web().with_assets(assets)
|
||||
};
|
||||
|
||||
let launch = move |cx: &mut App| {
|
||||
|
||||
Reference in New Issue
Block a user