From ac19c660c571f1bf35d7b3fa34d43ac914763b0b Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Wed, 13 Jan 2021 11:11:28 +0100 Subject: [PATCH] Update async-global-executor and add tokio feature for tokio 1.0 Co-authored-by: Yoshua Wuyts --- CHANGELOG.md | 4 ++++ Cargo.toml | 5 ++--- src/lib.rs | 9 +++++++++ src/rt/mod.rs | 2 +- src/task/spawn_blocking.rs | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e31829df..c16bbf64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview ## [Unreleased] +## Added + +- Add `tokio1` feature ([#924](https://github.com/async-rs/async-std/pull/924)) + # [1.8.0] - 2020-12-04 This patch introduces `async_std::channel`, a new submodule for our async channels implementation. `channels` have been one of async-std's most requested features, and have existed as "unstable" for the past year. We've been cautious about stabilizing channels, and this caution turned out to be warranted: we realized our channels could hang indefinitely under certain circumstances, and people ended up expressing a need for unbounded channels. diff --git a/Cargo.toml b/Cargo.toml index ef861ed4..9afb0e2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ default = [ "std", "async-global-executor", "async-io", - "blocking", "futures-lite", "kv-log-macro", "log", @@ -59,6 +58,7 @@ alloc = [ "futures-core/alloc", "pin-project-lite", ] +tokio1 = ["async-global-executor/tokio"] tokio02 = ["async-global-executor/tokio02"] tokio03 = ["async-global-executor/tokio03"] @@ -83,9 +83,8 @@ surf = { version = "2.0.0", optional = true } [target.'cfg(not(target_os = "unknown"))'.dependencies] -async-global-executor = { version = "1.4.0", optional = true, features = ["async-io"] } +async-global-executor = { version = "2.0.0", optional = true, features = ["async-io"] } async-io = { version = "1.0.1", optional = true } -blocking = { version = "1.0.0", optional = true } futures-lite = { version = "1.0.0", optional = true } async-process = { version = "1.0.1", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 22495d36..9a1c00c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -213,6 +213,15 @@ //! features = ["attributes"] //! ``` //! +//! Compatibility with the `tokio` 1.0 runtime is also simultaneously possible +//! using the `tokio1` Cargo feature: +//! +//! ```toml +//! [dependencies.async-std] +//! version = "1.7.0" +//! features = ["tokio1"] +//! ``` +//! //! Compatibility with the `tokio` 0.2 runtime is possible using the `tokio02` //! Cargo feature: //! diff --git a/src/rt/mod.rs b/src/rt/mod.rs index da78d9f8..80f1c4e6 100644 --- a/src/rt/mod.rs +++ b/src/rt/mod.rs @@ -12,7 +12,7 @@ pub static RUNTIME: Lazy = Lazy::new(|| { // Create an executor thread pool. let thread_name = env::var("ASYNC_STD_THREAD_NAME").unwrap_or_else(|_| "async-std/runtime".to_string()); - async_global_executor::init_with_config(async_global_executor::GlobalExecutorConfig::default().with_env_var("ASYNC_STD_THREAD_COUNT").with_thread_name(thread_name)); + async_global_executor::init_with_config(async_global_executor::GlobalExecutorConfig::default().with_env_var("ASYNC_STD_THREAD_COUNT").with_thread_name_fn(move || thread_name.clone())); Runtime {} }); diff --git a/src/task/spawn_blocking.rs b/src/task/spawn_blocking.rs index 8d6f3a51..3c57a751 100644 --- a/src/task/spawn_blocking.rs +++ b/src/task/spawn_blocking.rs @@ -35,5 +35,5 @@ where F: FnOnce() -> T + Send + 'static, T: Send + 'static, { - task::spawn(blocking::unblock(f)) + task::spawn(async_global_executor::spawn_blocking(f)) }