- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.8k
 
Closed
Labels
A-tokioArea: The main tokio crateArea: The main tokio crateC-questionUser questions that are neither feature requests nor bug reportsUser questions that are neither feature requests nor bug reportsM-blockingModule: tokio/task/blockingModule: tokio/task/blocking
Description
If I want to run a blocking action, do I need to manually differentiate? Can you automatically To deal with?
async fn read_to_string(path: impl AsRef<Path>) -> io::Result<String> {
task::spawn_blocking(move || {
 // to do some thing block io
  std::fs::read_to_string(path)
});
}
allow replace to Auto deal with
async fn read_to_string(path: impl AsRef<Path>) -> io::Result<String> {
  std::fs::read_to_string(path)
}
Because there are many libraries many IO operations are blocked for historical reasons(Even rust Std libraries)
If you use manual differentiation, you'll end up with a huge amount of code。
“async_std” this crate can auto(Inspired by golang), for example doc.
https://async.rs/blog/stop-worrying-about-blocking-the-new-async-std-runtime/
Metadata
Metadata
Assignees
Labels
A-tokioArea: The main tokio crateArea: The main tokio crateC-questionUser questions that are neither feature requests nor bug reportsUser questions that are neither feature requests nor bug reportsM-blockingModule: tokio/task/blockingModule: tokio/task/blocking