2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-01-16 02:39:55 +00:00

switch to blocking

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
This commit is contained in:
Marc-Antoine Perennou 2020-07-22 09:12:48 +02:00
parent 25e0e1abdc
commit 2fe087bd0a
2 changed files with 4 additions and 5 deletions

View file

@ -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]

View file

@ -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()) })
}