From 18b1e9d35f789a26f5094ea5df855755c593ccde Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 11 Mar 2022 10:02:37 +0100 Subject: [PATCH] Don't starve main thread when lots of messages/events arrive at once --- crates/client/src/client.rs | 3 +++ crates/project/src/project.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 62d2c6fb31e780c89a26b7c35134d8ad2ef7869d..59110f73c643cfac93730a0ef5e1900d896397eb 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -631,6 +631,9 @@ impl Client { } else { log::info!("unhandled message {}", type_name); } + + // Don't starve the main thread when receiving lots of messages at once. + smol::future::yield_now().await; } } }) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 430c6875d0be02492223d1feaaef3071767585b3..2f84f702bec9a169af6767f0ed3695f8c6f0d6ae 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1278,6 +1278,9 @@ impl Project { this.update(&mut cx, |this, cx| { this.on_lsp_event(server_id, event, &language, cx) }); + + // Don't starve the main thread when lots of events arrive all at once. + smol::future::yield_now().await; } Some(()) }