diff --git a/Cargo.toml b/Cargo.toml index 2534c2bad..70ab8f6ad 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.2", optional = true } +blocking = { version = "0.4.6", optional = true } smol = { version = "0.1.17", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/src/fs/file.rs b/src/fs/file.rs index 2ff5643e7..eb73af794 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -315,7 +315,7 @@ impl Drop for File { // non-blocking fashion, but our only other option here is losing data remaining in the // write cache. Good task schedulers should be resilient to occasional blocking hiccups in // file destructors so we don't expect this to be a common problem in practice. - let _ = smol::block_on(self.flush()); + let _ = blocking::block_on(self.flush()); } } diff --git a/src/task/builder.rs b/src/task/builder.rs index 0024f8ab8..ab43d5587 100644 --- a/src/task/builder.rs +++ b/src/task/builder.rs @@ -169,7 +169,7 @@ impl Builder { // The first call should use run. smol::run(wrapped) } else { - smol::block_on(wrapped) + blocking::block_on(wrapped) }; num_nested_blocking.replace(num_nested_blocking.get() - 1); res diff --git a/src/task/spawn_blocking.rs b/src/task/spawn_blocking.rs index e9ed0c5a0..9c836f24b 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()) }) }