Skip to content

Commit d4c3993

Browse files
committed
switch to blocking
Signed-off-by: Marc-Antoine Perennou <[email protected]>
1 parent 442d3bc commit d4c3993

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ default = [
2626
"std",
2727
"async-io",
2828
"async-task",
29+
"blocking",
2930
"kv-log-macro",
3031
"log",
3132
"num_cpus",
@@ -79,6 +80,7 @@ surf = { version = "1.0.3", optional = true }
7980

8081
[target.'cfg(not(target_os = "unknown"))'.dependencies]
8182
async-io = { version = "0.1.5", optional = true }
83+
blocking = { version = "0.5.0", optional = true }
8284
smol = { version = "0.1.17", optional = true }
8385

8486
[target.'cfg(target_arch = "wasm32")'.dependencies]

src/task/spawn_blocking.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::task::{JoinHandle, Task};
1+
use crate::task::{self, JoinHandle};
22

33
/// Spawns a blocking task.
44
///
@@ -35,8 +35,5 @@ where
3535
F: FnOnce() -> T + Send + 'static,
3636
T: Send + 'static,
3737
{
38-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
39-
40-
let handle = smol::Task::blocking(async move { f() }).into();
41-
JoinHandle::new(handle, Task::new(None))
38+
task::spawn(async move { blocking::unblock!(f()) })
4239
}

0 commit comments

Comments
 (0)