Add a crate for spawning tokio tasks in Zed (#23857)

Part of https://github.com/zed-industries/zed/pull/21092

As we're already depending on and using `tokio` to run `reqwest`, I've
added a crate to make running tokio futures more convenient. This should
unblock the Bedrock Cloud Model provider PR.

Note that since the `gpui_tokio` code is nearly trivial glue and I
expect that it will be useful for the nascent GPUI ecosystem, I've
elected to license it under Apache 2, like GPUI itself, instead of our
normal GPL license for Zed code.

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-01-29 12:53:16 -08:00 committed by GitHub
parent ee0d2a8d94
commit bd21334013
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 116 additions and 17 deletions

View file

@ -36,6 +36,7 @@ futures.workspace = true
git.workspace = true
git_hosting_providers.workspace = true
gpui.workspace = true
gpui_tokio.workspace = true
http_client.workspace = true
language.workspace = true
language_extension.workspace = true

View file

@ -9,6 +9,7 @@ use futures::channel::mpsc;
use futures::{select, select_biased, AsyncRead, AsyncWrite, AsyncWriteExt, FutureExt, SinkExt};
use git::GitHostingProviderRegistry;
use gpui::{App, AppContext as _, Context, Entity, SemanticVersion, UpdateGlobal as _};
use gpui_tokio::Tokio;
use http_client::{read_proxy_from_env, Uri};
use language::LanguageRegistry;
use node_runtime::{NodeBinaryOptions, NodeRuntime};
@ -425,6 +426,7 @@ pub fn execute_run(
settings::init(cx);
let app_version = AppVersion::init(env!("ZED_PKG_VERSION"));
release_channel::init(app_version, cx);
gpui_tokio::init(cx);
HeadlessProject::init(cx);
@ -445,18 +447,21 @@ pub fn execute_run(
let proxy_url = read_proxy_settings(cx);
let http_client = Arc::new(
ReqwestClient::proxy_and_user_agent(
proxy_url,
&format!(
"Zed-Server/{} ({}; {})",
env!("CARGO_PKG_VERSION"),
std::env::consts::OS,
std::env::consts::ARCH
),
let http_client = {
let _guard = Tokio::handle(cx).enter();
Arc::new(
ReqwestClient::proxy_and_user_agent(
proxy_url,
&format!(
"Zed-Server/{} ({}; {})",
env!("CARGO_PKG_VERSION"),
std::env::consts::OS,
std::env::consts::ARCH
),
)
.expect("Could not start HTTP client"),
)
.expect("Could not start HTTP client"),
);
};
let node_runtime = NodeRuntime::new(http_client.clone(), node_settings_rx);