Skip to content

Commit

Permalink
switch to blocking
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
  • Loading branch information
Keruspe committed Jul 15, 2020
1 parent 000cae2 commit a6f6d04
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ default = [
"std",
"async-io",
"async-task",
"blocking",
"kv-log-macro",
"log",
"num_cpus",
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/task/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/task/spawn_blocking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::task::{JoinHandle, Task};
use crate::task::{self, JoinHandle};

/// Spawns a blocking task.
///
Expand Down Expand Up @@ -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()) })
}

0 comments on commit a6f6d04

Please sign in to comment.