Skip to content

Commit a6f6d04

Browse files
committed
switch to blocking
Signed-off-by: Marc-Antoine Perennou <[email protected]>
1 parent 000cae2 commit a6f6d04

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

Diff for: 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.2", optional = true }
83+
blocking = { version = "0.4.6", optional = true }
8284
smol = { version = "0.1.17", optional = true }
8385

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

Diff for: src/fs/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl Drop for File {
315315
// non-blocking fashion, but our only other option here is losing data remaining in the
316316
// write cache. Good task schedulers should be resilient to occasional blocking hiccups in
317317
// file destructors so we don't expect this to be a common problem in practice.
318-
let _ = smol::block_on(self.flush());
318+
let _ = blocking::block_on(self.flush());
319319
}
320320
}
321321

Diff for: src/task/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Builder {
169169
// The first call should use run.
170170
smol::run(wrapped)
171171
} else {
172-
smol::block_on(wrapped)
172+
blocking::block_on(wrapped)
173173
};
174174
num_nested_blocking.replace(num_nested_blocking.get() - 1);
175175
res

Diff for: 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)