diff --git a/Cargo.toml b/Cargo.toml index e748953d..36322d99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ default = [ "std", "async-io", "async-task", + "blocking", "kv-log-macro", "log", "num_cpus", @@ -79,6 +80,7 @@ surf = { version = "1.0.3", optional = true } [target.'cfg(not(target_os = "unknown"))'.dependencies] async-io = { version = "0.1.5", optional = true } +blocking = { version = "0.5.0", optional = true } smol = { version = "0.1.17", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/src/task/spawn_blocking.rs b/src/task/spawn_blocking.rs index e9ed0c5a..9c836f24 100644 --- a/src/task/spawn_blocking.rs +++ b/src/task/spawn_blocking.rs @@ -1,4 +1,4 @@ -use crate::task::{JoinHandle, Task}; +use crate::task::{self, JoinHandle}; /// Spawns a blocking task. /// @@ -35,8 +35,5 @@ where F: FnOnce() -> T + Send + 'static, T: Send + 'static, { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - - let handle = smol::Task::blocking(async move { f() }).into(); - JoinHandle::new(handle, Task::new(None)) + task::spawn(async move { blocking::unblock!(f()) }) }