diff --git a/CHANGELOG.md b/CHANGELOG.md index 77ab025a1..6e658eaac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,7 +135,7 @@ task::blocking(async { - Refactored the scheduling algorithm of our executor to use work stealing - Refactored the network driver, removing 400 lines of code -- Removed the `Send` bound from `task::block_on` +- Removed the `Send` bound from `thread::spawn_task` - Removed `Unpin` bound from `impl Stream for T` # [0.99.5] - 2019-09-12 diff --git a/README.md b/README.md index ae129aa16..b1e3556c3 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ $ cargo add async-std use async_std::task; fn main() { - task::block_on(async { + thread::spawn_task(async { println!("Hello, world!"); }) } @@ -72,7 +72,7 @@ async fn get() -> io::Result> { } fn main() { - task::block_on(async { + thread::spawn_task(async { let raw_response = get().await.expect("request"); let response = String::from_utf8(raw_response) .expect("utf8 conversion"); diff --git a/benches/task_local.rs b/benches/task_local.rs index 3b6c85902..ce432c171 100644 --- a/benches/task_local.rs +++ b/benches/task_local.rs @@ -13,7 +13,7 @@ fn get(b: &mut Bencher) { } let mut sum = 0; - task::block_on(async { + thread::spawn_task(async { b.iter(|| VAL.with(|v| sum += v)); }); black_box(sum); diff --git a/docs/src/concepts/tasks.md b/docs/src/concepts/tasks.md index d4037a3bb..858b59470 100644 --- a/docs/src/concepts/tasks.md +++ b/docs/src/concepts/tasks.md @@ -24,7 +24,7 @@ fn main() { } }); println!("Started task!"); - task::block_on(reader_task); + thread::spawn_task(reader_task); println!("Stopped task!"); } ``` @@ -86,7 +86,7 @@ Tasks in `async_std` are one of the core abstractions. Much like Rust's `thread` # extern crate async_std; # use async_std::task; fn main() { - task::block_on(async { + thread::spawn_task(async { // this is std::fs, which blocks std::fs::read_to_string("test_file"); }) @@ -107,7 +107,7 @@ In practice, that means that `block_on` propagates panics to the blocking compon # extern crate async_std; # use async_std::task; fn main() { - task::block_on(async { + thread::spawn_task(async { panic!("test"); }); } @@ -128,7 +128,7 @@ task::spawn(async { panic!("test"); }); -task::block_on(async { +thread::spawn_task(async { task::sleep(Duration::from_millis(10000)).await; }) ``` diff --git a/docs/src/tutorial/accept_loop.md b/docs/src/tutorial/accept_loop.md index dc748bb4d..e1b6464dc 100644 --- a/docs/src/tutorial/accept_loop.md +++ b/docs/src/tutorial/accept_loop.md @@ -85,7 +85,7 @@ Finally, let's add main: // main fn run() -> Result<()> { let fut = accept_loop("127.0.0.1:8080"); - task::block_on(fut) + thread::spawn_task(fut) } ``` @@ -93,4 +93,4 @@ The crucial thing to realise that is in Rust, unlike other languages, calling an Async functions only construct futures, which are inert state machines. To start stepping through the future state-machine in an async function, you should use `.await`. In a non-async function, a way to execute a future is to hand it to the executor. -In this case, we use `task::block_on` to execute a future on the current thread and block until it's done. +In this case, we use `thread::spawn_task` to execute a future on the current thread and block until it's done. diff --git a/docs/src/tutorial/all_together.md b/docs/src/tutorial/all_together.md index dcc06616a..b030183a1 100644 --- a/docs/src/tutorial/all_together.md +++ b/docs/src/tutorial/all_together.md @@ -25,7 +25,7 @@ type Receiver = mpsc::UnboundedReceiver; // main fn run() -> Result<()> { - task::block_on(accept_loop("127.0.0.1:8080")) + thread::spawn_task(accept_loop("127.0.0.1:8080")) } fn spawn_and_log_error(fut: F) -> task::JoinHandle<()> diff --git a/docs/src/tutorial/handling_disconnection.md b/docs/src/tutorial/handling_disconnection.md index a1f51d134..c4a3f2f63 100644 --- a/docs/src/tutorial/handling_disconnection.md +++ b/docs/src/tutorial/handling_disconnection.md @@ -147,7 +147,7 @@ enum Void {} // main fn run() -> Result<()> { - task::block_on(accept_loop("127.0.0.1:8080")) + thread::spawn_task(accept_loop("127.0.0.1:8080")) } async fn accept_loop(addr: impl ToSocketAddrs) -> Result<()> { diff --git a/docs/src/tutorial/implementing_a_client.md b/docs/src/tutorial/implementing_a_client.md index 3aac67f35..a8cb34b8c 100644 --- a/docs/src/tutorial/implementing_a_client.md +++ b/docs/src/tutorial/implementing_a_client.md @@ -29,7 +29,7 @@ type Result = std::result::Result // main fn run() -> Result<()> { - task::block_on(try_run("127.0.0.1:8080")) + thread::spawn_task(try_run("127.0.0.1:8080")) } async fn try_run(addr: impl ToSocketAddrs) -> Result<()> { diff --git a/examples/a-chat/client.rs b/examples/a-chat/client.rs index 48634ba03..fddfd1b3b 100644 --- a/examples/a-chat/client.rs +++ b/examples/a-chat/client.rs @@ -5,13 +5,13 @@ use async_std::{ io::{stdin, BufReader}, net::{TcpStream, ToSocketAddrs}, prelude::*, - task, + thread, }; type Result = std::result::Result>; pub(crate) fn main() -> Result<()> { - task::block_on(try_main("127.0.0.1:8080")) + thread::spawn_task(try_main("127.0.0.1:8080")) } async fn try_main(addr: impl ToSocketAddrs) -> Result<()> { diff --git a/examples/a-chat/server.rs b/examples/a-chat/server.rs index 77ebfd1e3..e5669219e 100644 --- a/examples/a-chat/server.rs +++ b/examples/a-chat/server.rs @@ -10,6 +10,7 @@ use async_std::{ net::{TcpListener, TcpStream, ToSocketAddrs}, prelude::*, task, + thread, }; type Result = std::result::Result>; @@ -20,7 +21,7 @@ type Receiver = mpsc::UnboundedReceiver; enum Void {} pub(crate) fn main() -> Result<()> { - task::block_on(accept_loop("127.0.0.1:8080")) + thread::spawn_task(accept_loop("127.0.0.1:8080")) } async fn accept_loop(addr: impl ToSocketAddrs) -> Result<()> { diff --git a/examples/hello-world.rs b/examples/hello-world.rs index 8d663339f..259f56438 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -1,11 +1,11 @@ //! Spawns a task that says hello. -use async_std::task; +use async_std::thread; async fn say_hi() { println!("Hello, world!"); } fn main() { - task::block_on(say_hi()) + thread::spawn_task(say_hi()) } diff --git a/examples/line-count.rs b/examples/line-count.rs index 847352d62..dafba774b 100644 --- a/examples/line-count.rs +++ b/examples/line-count.rs @@ -5,12 +5,12 @@ use std::env::args; use async_std::fs::File; use async_std::io::{self, BufReader}; use async_std::prelude::*; -use async_std::task; +use async_std::thread; fn main() -> io::Result<()> { let path = args().nth(1).expect("missing path argument"); - task::block_on(async { + thread::spawn_task(async { let file = File::open(&path).await?; let mut lines = BufReader::new(file).lines(); let mut count = 0u64; diff --git a/examples/list-dir.rs b/examples/list-dir.rs index e4b62fc3a..afacdbc65 100644 --- a/examples/list-dir.rs +++ b/examples/list-dir.rs @@ -5,12 +5,12 @@ use std::env::args; use async_std::fs; use async_std::io; use async_std::prelude::*; -use async_std::task; +use async_std::thread; fn main() -> io::Result<()> { let path = args().nth(1).expect("missing path argument"); - task::block_on(async { + thread::spawn_task(async { let mut dir = fs::read_dir(&path).await?; while let Some(res) = dir.next().await { diff --git a/examples/logging.rs b/examples/logging.rs index bd55aaa0c..825751825 100644 --- a/examples/logging.rs +++ b/examples/logging.rs @@ -1,11 +1,12 @@ //! Prints the runtime's execution log on the standard output. +use async_std::thread; use async_std::task; fn main() { femme::start(log::LevelFilter::Trace).unwrap(); - task::block_on(async { + thread::spawn_task(async { let handle = task::spawn(async { log::info!("Hello world!"); }); diff --git a/examples/print-file.rs b/examples/print-file.rs index e2cdde794..c2febd716 100644 --- a/examples/print-file.rs +++ b/examples/print-file.rs @@ -5,14 +5,14 @@ use std::env::args; use async_std::fs::File; use async_std::io; use async_std::prelude::*; -use async_std::task; +use async_std::thread; const LEN: usize = 16 * 1024; // 16 Kb fn main() -> io::Result<()> { let path = args().nth(1).expect("missing path argument"); - task::block_on(async { + thread::spawn_task(async { let mut file = File::open(&path).await?; let mut stdout = io::stdout(); let mut buf = vec![0u8; LEN]; diff --git a/examples/socket-timeouts.rs b/examples/socket-timeouts.rs index f4db5c7b2..d1cdf28a8 100644 --- a/examples/socket-timeouts.rs +++ b/examples/socket-timeouts.rs @@ -2,7 +2,8 @@ use std::time::Duration; -use async_std::{io, net::TcpStream, prelude::*, task}; +use async_std::{io, net::TcpStream, prelude::*}; +use async_std::thread; async fn get() -> io::Result> { let mut stream = TcpStream::connect("example.com:80").await?; @@ -20,7 +21,7 @@ async fn get() -> io::Result> { } fn main() { - task::block_on(async { + thread::spawn_task(async { let raw_response = get().await.expect("request"); let response = String::from_utf8(raw_response).expect("utf8 conversion"); println!("received: {}", response); diff --git a/examples/stdin-echo.rs b/examples/stdin-echo.rs index 9514219e8..0bceedd20 100644 --- a/examples/stdin-echo.rs +++ b/examples/stdin-echo.rs @@ -2,10 +2,10 @@ use async_std::io; use async_std::prelude::*; -use async_std::task; +use async_std::thread; fn main() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let stdin = io::stdin(); let mut stdout = io::stdout(); let mut line = String::new(); diff --git a/examples/stdin-timeout.rs b/examples/stdin-timeout.rs index f13c38748..5e5b2f25e 100644 --- a/examples/stdin-timeout.rs +++ b/examples/stdin-timeout.rs @@ -3,11 +3,11 @@ use std::time::Duration; use async_std::io; -use async_std::task; +use async_std::thread; fn main() -> io::Result<()> { // This async scope times out after 5 seconds. - task::block_on(io::timeout(Duration::from_secs(5), async { + thread::spawn_task(io::timeout(Duration::from_secs(5), async { let stdin = io::stdin(); // Read a line from the standard input and display it. diff --git a/examples/surf-web.rs b/examples/surf-web.rs index b3101d15c..863e5f174 100644 --- a/examples/surf-web.rs +++ b/examples/surf-web.rs @@ -1,10 +1,10 @@ /* TODO: Once the next version of surf released, re-enable this example. //! Sends an HTTP request to the Rust website. -use async_std::task; +use async_std::thread; fn main() -> Result<(), surf::Exception> { - task::block_on(async { + thread::spawn_task(async { let url = "https://www.rust-lang.org"; let mut response = surf::get(url).await?; let body = response.body_string().await?; diff --git a/examples/task-local.rs b/examples/task-local.rs index 320b383e1..18e5809fb 100644 --- a/examples/task-local.rs +++ b/examples/task-local.rs @@ -3,14 +3,14 @@ use std::cell::Cell; use async_std::prelude::*; -use async_std::task; +use async_std::thread; task_local! { static VAR: Cell = Cell::new(1); } fn main() { - task::block_on(async { + thread::spawn_task(async { println!("var = {}", VAR.with(|v| v.get())); VAR.with(|v| v.set(2)); println!("var = {}", VAR.with(|v| v.get())); diff --git a/examples/task-name.rs b/examples/task-name.rs index f0bfdff86..b3bcb51aa 100644 --- a/examples/task-name.rs +++ b/examples/task-name.rs @@ -1,13 +1,14 @@ //! Spawns a named task that prints its name. use async_std::task; +use async_std::thread; async fn print_name() { println!("My name is {:?}", task::current().name()); } fn main() { - task::block_on(async { + thread::spawn_task(async { task::Builder::new() .name("my-task".to_string()) .spawn(print_name()) diff --git a/examples/tcp-client.rs b/examples/tcp-client.rs index 02250eec5..4903cfb53 100644 --- a/examples/tcp-client.rs +++ b/examples/tcp-client.rs @@ -15,10 +15,10 @@ use async_std::io; use async_std::net::TcpStream; use async_std::prelude::*; -use async_std::task; +use async_std::thread; fn main() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let mut stream = TcpStream::connect("127.0.0.1:8080").await?; println!("Connected to {}", &stream.peer_addr()?); diff --git a/examples/tcp-echo.rs b/examples/tcp-echo.rs index 7c50be016..f9fa3ee03 100644 --- a/examples/tcp-echo.rs +++ b/examples/tcp-echo.rs @@ -9,6 +9,7 @@ use async_std::io; use async_std::net::{TcpListener, TcpStream}; use async_std::prelude::*; +use async_std::thread; use async_std::task; async fn process(stream: TcpStream) -> io::Result<()> { @@ -21,7 +22,7 @@ async fn process(stream: TcpStream) -> io::Result<()> { } fn main() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let listener = TcpListener::bind("127.0.0.1:8080").await?; println!("Listening on {}", listener.local_addr()?); diff --git a/examples/udp-client.rs b/examples/udp-client.rs index 180db0b83..7efd7dec4 100644 --- a/examples/udp-client.rs +++ b/examples/udp-client.rs @@ -14,10 +14,10 @@ use async_std::io; use async_std::net::UdpSocket; -use async_std::task; +use async_std::thread; fn main() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let socket = UdpSocket::bind("127.0.0.1:8081").await?; println!("Listening on {}", socket.local_addr()?); diff --git a/examples/udp-echo.rs b/examples/udp-echo.rs index f436d01bd..4b75d9b3a 100644 --- a/examples/udp-echo.rs +++ b/examples/udp-echo.rs @@ -8,10 +8,10 @@ use async_std::io; use async_std::net::UdpSocket; -use async_std::task; +use async_std::thread; fn main() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let socket = UdpSocket::bind("127.0.0.1:8080").await?; let mut buf = vec![0u8; 1024]; diff --git a/src/fs/canonicalize.rs b/src/fs/canonicalize.rs index c484aeeb5..65a1bd825 100644 --- a/src/fs/canonicalize.rs +++ b/src/fs/canonicalize.rs @@ -23,7 +23,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/copy.rs b/src/fs/copy.rs index fc3fd3e69..0893ee820 100644 --- a/src/fs/copy.rs +++ b/src/fs/copy.rs @@ -31,7 +31,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/create_dir.rs b/src/fs/create_dir.rs index aa2d5724f..9d12ced9b 100644 --- a/src/fs/create_dir.rs +++ b/src/fs/create_dir.rs @@ -25,7 +25,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/create_dir_all.rs b/src/fs/create_dir_all.rs index 33176f75d..f6c25c5db 100644 --- a/src/fs/create_dir_all.rs +++ b/src/fs/create_dir_all.rs @@ -20,7 +20,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/dir_builder.rs b/src/fs/dir_builder.rs index 3064f7a30..39bb85cb0 100644 --- a/src/fs/dir_builder.rs +++ b/src/fs/dir_builder.rs @@ -86,7 +86,7 @@ impl DirBuilder { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::DirBuilder; /// diff --git a/src/fs/dir_entry.rs b/src/fs/dir_entry.rs index 66b3cb7c9..509a2beda 100644 --- a/src/fs/dir_entry.rs +++ b/src/fs/dir_entry.rs @@ -35,7 +35,7 @@ impl DirEntry { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// use async_std::prelude::*; @@ -73,7 +73,7 @@ impl DirEntry { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// use async_std::prelude::*; @@ -111,7 +111,7 @@ impl DirEntry { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// use async_std::prelude::*; @@ -135,7 +135,7 @@ impl DirEntry { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// use async_std::prelude::*; diff --git a/src/fs/file.rs b/src/fs/file.rs index bdf934748..dcff25c5c 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -15,6 +15,7 @@ use crate::future; use crate::io::{self, Read, Seek, SeekFrom, Write}; use crate::prelude::*; use crate::task::{self, blocking, Context, Poll, Waker}; +use crate::thread; /// An open file on the filesystem. /// @@ -34,7 +35,7 @@ use crate::task::{self, blocking, Context, Poll, Waker}; /// Create a new file and write some bytes to it: /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::prelude::*; @@ -48,7 +49,7 @@ use crate::task::{self, blocking, Context, Poll, Waker}; /// Read the contents of a file into a vector of bytes: /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::prelude::*; @@ -87,7 +88,7 @@ impl File { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// @@ -122,7 +123,7 @@ impl File { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// @@ -146,7 +147,7 @@ impl File { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::prelude::*; @@ -182,7 +183,7 @@ impl File { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::prelude::*; @@ -216,7 +217,7 @@ impl File { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// @@ -242,7 +243,7 @@ impl File { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// @@ -268,7 +269,7 @@ impl File { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// @@ -292,7 +293,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 _ = task::block_on(self.flush()); + let _ = thread::spawn_task(self.flush()); } } diff --git a/src/fs/file_type.rs b/src/fs/file_type.rs index a1627984c..80a0851dd 100644 --- a/src/fs/file_type.rs +++ b/src/fs/file_type.rs @@ -29,7 +29,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -49,7 +49,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -67,7 +67,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/hard_link.rs b/src/fs/hard_link.rs index 5f950cde1..4d42562a9 100644 --- a/src/fs/hard_link.rs +++ b/src/fs/hard_link.rs @@ -22,7 +22,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/metadata.rs b/src/fs/metadata.rs index 2c9e41ecd..cff9d2899 100644 --- a/src/fs/metadata.rs +++ b/src/fs/metadata.rs @@ -27,7 +27,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -68,7 +68,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -88,7 +88,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -108,7 +108,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -126,7 +126,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -144,7 +144,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -167,7 +167,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -190,7 +190,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -213,7 +213,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 4598ec849..58ae5a231 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -14,7 +14,7 @@ //! Create a new file and write some bytes to it: //! //! ```no_run -//! # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +//! # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { //! # //! use async_std::fs::File; //! use async_std::prelude::*; diff --git a/src/fs/open_options.rs b/src/fs/open_options.rs index 252873cd2..32f76c7ea 100644 --- a/src/fs/open_options.rs +++ b/src/fs/open_options.rs @@ -32,7 +32,7 @@ use crate::task::blocking; /// Open a file for reading: /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -47,7 +47,7 @@ use crate::task::blocking; /// Open a file for both reading and writing, and create it if it doesn't exist yet: /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -71,7 +71,7 @@ impl OpenOptions { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -93,7 +93,7 @@ impl OpenOptions { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -119,7 +119,7 @@ impl OpenOptions { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -143,7 +143,7 @@ impl OpenOptions { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -171,7 +171,7 @@ impl OpenOptions { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -200,7 +200,7 @@ impl OpenOptions { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -230,7 +230,7 @@ impl OpenOptions { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// @@ -272,7 +272,7 @@ impl OpenOptions { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::OpenOptions; /// diff --git a/src/fs/permissions.rs b/src/fs/permissions.rs index 628dd392b..46356d848 100644 --- a/src/fs/permissions.rs +++ b/src/fs/permissions.rs @@ -18,7 +18,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// @@ -38,7 +38,7 @@ cfg_if! { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/read.rs b/src/fs/read.rs index 6b3560db7..a41d82211 100644 --- a/src/fs/read.rs +++ b/src/fs/read.rs @@ -27,7 +27,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/read_dir.rs b/src/fs/read_dir.rs index 9b4269df2..3c9ae67b1 100644 --- a/src/fs/read_dir.rs +++ b/src/fs/read_dir.rs @@ -29,7 +29,7 @@ use crate::task::{blocking, Context, JoinHandle, Poll}; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// use async_std::prelude::*; diff --git a/src/fs/read_link.rs b/src/fs/read_link.rs index aede99bc8..8b4637194 100644 --- a/src/fs/read_link.rs +++ b/src/fs/read_link.rs @@ -19,7 +19,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/read_to_string.rs b/src/fs/read_to_string.rs index 345f76efa..4bf0e3d6c 100644 --- a/src/fs/read_to_string.rs +++ b/src/fs/read_to_string.rs @@ -28,7 +28,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/remove_dir.rs b/src/fs/remove_dir.rs index a176edc85..69fe20de3 100644 --- a/src/fs/remove_dir.rs +++ b/src/fs/remove_dir.rs @@ -20,7 +20,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/remove_dir_all.rs b/src/fs/remove_dir_all.rs index 9db0c31f5..c9caa159c 100644 --- a/src/fs/remove_dir_all.rs +++ b/src/fs/remove_dir_all.rs @@ -20,7 +20,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/remove_file.rs b/src/fs/remove_file.rs index cc0eeb259..b0a6f64c8 100644 --- a/src/fs/remove_file.rs +++ b/src/fs/remove_file.rs @@ -20,7 +20,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/rename.rs b/src/fs/rename.rs index 72cd227f9..6b746c172 100644 --- a/src/fs/rename.rs +++ b/src/fs/rename.rs @@ -24,7 +24,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/set_permissions.rs b/src/fs/set_permissions.rs index 6fa6306fc..dceb9da90 100644 --- a/src/fs/set_permissions.rs +++ b/src/fs/set_permissions.rs @@ -21,7 +21,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/symlink_metadata.rs b/src/fs/symlink_metadata.rs index 6f1b9d501..b81bc93c1 100644 --- a/src/fs/symlink_metadata.rs +++ b/src/fs/symlink_metadata.rs @@ -25,7 +25,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/fs/write.rs b/src/fs/write.rs index b0d7abcc2..ac0bff541 100644 --- a/src/fs/write.rs +++ b/src/fs/write.rs @@ -23,7 +23,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs; /// diff --git a/src/future/pending.rs b/src/future/pending.rs index aaee70656..f944a4a8e 100644 --- a/src/future/pending.rs +++ b/src/future/pending.rs @@ -9,7 +9,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use std::time::Duration; /// diff --git a/src/future/poll_fn.rs b/src/future/poll_fn.rs index 116e71c69..56c6bad6b 100644 --- a/src/future/poll_fn.rs +++ b/src/future/poll_fn.rs @@ -10,7 +10,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::future; /// use async_std::task::{Context, Poll}; diff --git a/src/future/ready.rs b/src/future/ready.rs index 04f37b87c..534318167 100644 --- a/src/future/ready.rs +++ b/src/future/ready.rs @@ -7,7 +7,7 @@ /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::future; /// diff --git a/src/future/timeout.rs b/src/future/timeout.rs index aa88f6461..c3293acdf 100644 --- a/src/future/timeout.rs +++ b/src/future/timeout.rs @@ -16,7 +16,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use std::time::Duration; /// diff --git a/src/io/buf_read/mod.rs b/src/io/buf_read/mod.rs index d34b2ae26..675c7bf98 100644 --- a/src/io/buf_read/mod.rs +++ b/src/io/buf_read/mod.rs @@ -77,7 +77,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::io::BufReader; @@ -94,7 +94,7 @@ extension_trait! { Multiple successful calls to `read_until` append all bytes up to and including to `buf`: ``` - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::io::BufReader; use async_std::prelude::*; @@ -155,7 +155,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::io::BufReader; @@ -197,7 +197,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::io::BufReader; diff --git a/src/io/buf_reader.rs b/src/io/buf_reader.rs index 13cb4cc56..5972475f8 100644 --- a/src/io/buf_reader.rs +++ b/src/io/buf_reader.rs @@ -29,7 +29,7 @@ const DEFAULT_CAPACITY: usize = 8 * 1024; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::io::BufReader; @@ -57,7 +57,7 @@ impl BufReader { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::io::BufReader; @@ -75,7 +75,7 @@ impl BufReader { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::io::BufReader; @@ -106,7 +106,7 @@ impl BufReader { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::io::BufReader; @@ -127,7 +127,7 @@ impl BufReader { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::io::BufReader; @@ -148,7 +148,7 @@ impl BufReader { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::io::BufReader; @@ -169,7 +169,7 @@ impl BufReader { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::fs::File; /// use async_std::io::BufReader; diff --git a/src/io/buf_writer.rs b/src/io/buf_writer.rs index 2b7545a1f..719229946 100644 --- a/src/io/buf_writer.rs +++ b/src/io/buf_writer.rs @@ -35,7 +35,7 @@ const DEFAULT_CAPACITY: usize = 8 * 1024; /// Let's write the numbers one through ten to a [`TcpStream`]: /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use async_std::net::TcpStream; /// use async_std::prelude::*; /// @@ -54,7 +54,7 @@ const DEFAULT_CAPACITY: usize = 8 * 1024; /// `BufWriter`: /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use async_std::io::BufWriter; /// use async_std::net::TcpStream; /// use async_std::prelude::*; @@ -93,7 +93,7 @@ impl BufWriter { /// /// ```no_run /// # #![allow(unused_mut)] - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use async_std::io::BufWriter; /// use async_std::net::TcpStream; /// @@ -113,7 +113,7 @@ impl BufWriter { /// /// ```no_run /// # #![allow(unused_mut)] - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use async_std::io::BufWriter; /// use async_std::net::TcpStream; /// @@ -136,7 +136,7 @@ impl BufWriter { /// /// ```no_run /// # #![allow(unused_mut)] - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use async_std::io::BufWriter; /// use async_std::net::TcpStream; /// @@ -158,7 +158,7 @@ impl BufWriter { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use async_std::io::BufWriter; /// use async_std::net::TcpStream; /// @@ -196,7 +196,7 @@ impl BufWriter { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use async_std::io::BufWriter; /// use async_std::net::TcpStream; /// @@ -308,11 +308,11 @@ mod tests { use super::BufWriter; use crate::io::{self, SeekFrom}; use crate::prelude::*; - use crate::task; + use crate::thread; #[test] fn test_buffered_writer() { - task::block_on(async { + thread::spawn_task(async { let inner = Vec::new(); let mut writer = BufWriter::with_capacity(2, inner); @@ -357,7 +357,7 @@ mod tests { #[test] fn test_buffered_writer_inner_into_inner_does_not_flush() { - task::block_on(async { + thread::spawn_task(async { let mut w = BufWriter::with_capacity(3, Vec::new()); w.write(&[0, 1]).await.unwrap(); assert_eq!(*w.get_ref(), []); @@ -368,7 +368,7 @@ mod tests { #[test] fn test_buffered_writer_seek() { - task::block_on(async { + thread::spawn_task(async { let mut w = BufWriter::with_capacity(3, io::Cursor::new(Vec::new())); w.write_all(&[0, 1, 2, 3, 4, 5]).await.unwrap(); w.write_all(&[6, 7]).await.unwrap(); diff --git a/src/io/copy.rs b/src/io/copy.rs index 3840d2af9..1b26fca4a 100644 --- a/src/io/copy.rs +++ b/src/io/copy.rs @@ -30,7 +30,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// diff --git a/src/io/cursor.rs b/src/io/cursor.rs index 603b85a14..0d982b1fc 100644 --- a/src/io/cursor.rs +++ b/src/io/cursor.rs @@ -107,7 +107,7 @@ impl Cursor { /// # Examples /// /// ``` - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io::Cursor; /// use async_std::io::prelude::*; diff --git a/src/io/empty.rs b/src/io/empty.rs index d8d768e02..e8bfe2d8c 100644 --- a/src/io/empty.rs +++ b/src/io/empty.rs @@ -9,7 +9,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ```rust -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// use async_std::prelude::*; diff --git a/src/io/mod.rs b/src/io/mod.rs index 7a9428544..e582b2b36 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -9,7 +9,7 @@ //! Read a line from the standard input: //! //! ```no_run -//! # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +//! # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { //! # //! use async_std::io; //! diff --git a/src/io/read/bytes.rs b/src/io/read/bytes.rs index 422452433..9d28a9398 100644 --- a/src/io/read/bytes.rs +++ b/src/io/read/bytes.rs @@ -36,11 +36,11 @@ impl Stream for Bytes { mod tests { use crate::io; use crate::prelude::*; - use crate::task; + use crate::thread; #[test] fn test_bytes_basics() -> std::io::Result<()> { - task::block_on(async move { + thread::spawn_task(async move { let raw: Vec = vec![0, 1, 2, 3, 4, 5, 6, 7, 8]; let source: io::Cursor> = io::Cursor::new(raw.clone()); diff --git a/src/io/read/chain.rs b/src/io/read/chain.rs index 09517ccad..d35490de1 100644 --- a/src/io/read/chain.rs +++ b/src/io/read/chain.rs @@ -23,7 +23,7 @@ impl Chain { /// # Examples /// /// ```no_run - /// # fn main() -> async_std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> async_std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::fs::File; @@ -45,7 +45,7 @@ impl Chain { /// # Examples /// /// ```no_run - /// # fn main() -> async_std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> async_std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::fs::File; @@ -71,7 +71,7 @@ impl Chain { /// # Examples /// /// ```no_run - /// # fn main() -> async_std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> async_std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::fs::File; @@ -176,14 +176,14 @@ impl BufRead for Chain { mod tests { use crate::io; use crate::prelude::*; - use crate::task; + use crate::thread; #[test] fn test_chain_basics() -> std::io::Result<()> { let source1: io::Cursor> = io::Cursor::new(vec![0, 1, 2]); let source2: io::Cursor> = io::Cursor::new(vec![3, 4, 5]); - task::block_on(async move { + thread::spawn_task(async move { let mut buffer = Vec::new(); let mut source = source1.chain(source2); diff --git a/src/io/read/mod.rs b/src/io/read/mod.rs index 6fd95c120..1cc4eeafc 100644 --- a/src/io/read/mod.rs +++ b/src/io/read/mod.rs @@ -89,7 +89,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::prelude::*; @@ -148,7 +148,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::prelude::*; @@ -187,7 +187,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::prelude::*; @@ -242,7 +242,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::prelude::*; @@ -282,7 +282,7 @@ extension_trait! { [`read()`]: tymethod.read ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::io::prelude::*; use async_std::fs::File; @@ -318,7 +318,7 @@ extension_trait! { [file]: ../fs/struct.File.html ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::fs::File; @@ -359,7 +359,7 @@ extension_trait! { [file]: ../fs/struct.File.html ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::fs::File; @@ -392,7 +392,7 @@ extension_trait! { [file]: ../fs/struct.File.html ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::fs::File; @@ -477,7 +477,7 @@ mod tests { #[test] fn test_read_by_ref() -> io::Result<()> { - crate::task::block_on(async { + crate::thread::spawn_task(async { let mut f = io::Cursor::new(vec![0u8, 1, 2, 3, 4, 5, 6, 7, 8]); let mut buffer = Vec::new(); let mut other_buffer = Vec::new(); diff --git a/src/io/read/take.rs b/src/io/read/take.rs index def4e2405..26d0e297b 100644 --- a/src/io/read/take.rs +++ b/src/io/read/take.rs @@ -30,7 +30,7 @@ impl Take { /// # Examples /// /// ```no_run - /// # fn main() -> async_std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> async_std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::fs::File; @@ -56,7 +56,7 @@ impl Take { /// # Examples /// /// ```no_run - /// # fn main() -> async_std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> async_std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::fs::File; @@ -80,7 +80,7 @@ impl Take { /// # Examples /// /// ```no_run - /// # fn main() -> async_std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> async_std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::fs::File; @@ -104,7 +104,7 @@ impl Take { /// # Examples /// /// ```no_run - /// # fn main() -> async_std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> async_std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::fs::File; @@ -132,7 +132,7 @@ impl Take { /// # Examples /// /// ```no_run - /// # fn main() -> async_std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> async_std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::fs::File; @@ -218,13 +218,13 @@ impl BufRead for Take { mod tests { use crate::io; use crate::prelude::*; - use crate::task; + use crate::thread; #[test] fn test_take_basics() -> std::io::Result<()> { let source: io::Cursor> = io::Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7, 8]); - task::block_on(async move { + thread::spawn_task(async move { let mut buffer = [0u8; 5]; // read at most five bytes diff --git a/src/io/repeat.rs b/src/io/repeat.rs index a82e21be4..f259e5529 100644 --- a/src/io/repeat.rs +++ b/src/io/repeat.rs @@ -11,7 +11,7 @@ use crate::task::{Context, Poll}; /// ## Examples /// /// ```rust -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// use async_std::prelude::*; diff --git a/src/io/seek.rs b/src/io/seek.rs index 274eee736..dd33e0b0d 100644 --- a/src/io/seek.rs +++ b/src/io/seek.rs @@ -54,7 +54,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::io::SeekFrom; diff --git a/src/io/sink.rs b/src/io/sink.rs index faa763c6a..0b97fb100 100644 --- a/src/io/sink.rs +++ b/src/io/sink.rs @@ -9,7 +9,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ```rust -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// use async_std::prelude::*; diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 5706aa2ed..cecbcc6dd 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -16,7 +16,7 @@ use crate::task::{blocking, Context, JoinHandle, Poll}; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// use async_std::prelude::*; diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 95a77b805..118e95a60 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -16,7 +16,7 @@ use crate::task::{blocking, Context, JoinHandle, Poll}; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// @@ -89,7 +89,7 @@ impl Stdin { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// diff --git a/src/io/stdout.rs b/src/io/stdout.rs index 7849f1ce9..2c32d9e90 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -16,7 +16,7 @@ use crate::task::{blocking, Context, JoinHandle, Poll}; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// use async_std::prelude::*; diff --git a/src/io/timeout.rs b/src/io/timeout.rs index 2d1b29e74..de7df942c 100644 --- a/src/io/timeout.rs +++ b/src/io/timeout.rs @@ -13,7 +13,7 @@ use crate::io; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use std::time::Duration; /// diff --git a/src/io/write/mod.rs b/src/io/write/mod.rs index 5e1ecc8be..5b9ebbe88 100644 --- a/src/io/write/mod.rs +++ b/src/io/write/mod.rs @@ -92,7 +92,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::prelude::*; @@ -120,7 +120,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::prelude::*; @@ -174,7 +174,7 @@ extension_trait! { # Examples ```no_run - # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { # use async_std::fs::File; use async_std::prelude::*; diff --git a/src/lib.rs b/src/lib.rs index fa4e946f9..962fca7d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,10 +17,10 @@ //! Spawn a task and block the current thread on its result: //! //! ``` -//! use async_std::task; +//! use async_std::thread; //! //! fn main() { -//! task::block_on(async { +//! thread::spawn_task(async { //! println!("Hello, world!"); //! }) //! } @@ -59,6 +59,7 @@ pub mod prelude; pub mod stream; pub mod sync; pub mod task; +pub mod thread; cfg_if! { if #[cfg(any(feature = "unstable", feature = "docs"))] { diff --git a/src/net/addr.rs b/src/net/addr.rs index 64b22cfcd..13018b5ac 100644 --- a/src/net/addr.rs +++ b/src/net/addr.rs @@ -34,7 +34,7 @@ cfg_if! { /// # Examples /// /// ``` -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::ToSocketAddrs; /// diff --git a/src/net/mod.rs b/src/net/mod.rs index b3ae287fa..19b5daece 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -13,7 +13,7 @@ //! A simple UDP echo server: //! //! ```no_run -//! # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +//! # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { //! # //! use async_std::net::UdpSocket; //! diff --git a/src/net/tcp/listener.rs b/src/net/tcp/listener.rs index 26e19d79f..5c8ff65ef 100644 --- a/src/net/tcp/listener.rs +++ b/src/net/tcp/listener.rs @@ -31,7 +31,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::io; /// use async_std::net::TcpListener; @@ -65,7 +65,7 @@ impl TcpListener { /// Create a TCP listener bound to 127.0.0.1:0: /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpListener; /// @@ -104,7 +104,7 @@ impl TcpListener { /// ## Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpListener; /// @@ -136,7 +136,7 @@ impl TcpListener { /// ## Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpListener; /// use async_std::prelude::*; @@ -163,7 +163,7 @@ impl TcpListener { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpListener; /// diff --git a/src/net/tcp/stream.rs b/src/net/tcp/stream.rs index 10569434e..26827523a 100644 --- a/src/net/tcp/stream.rs +++ b/src/net/tcp/stream.rs @@ -34,7 +34,7 @@ use crate::task::{Context, Poll}; /// ## Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// use async_std::prelude::*; @@ -64,7 +64,7 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// @@ -104,7 +104,7 @@ impl TcpStream { /// ## Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// @@ -122,7 +122,7 @@ impl TcpStream { /// ## Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// @@ -144,7 +144,7 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// @@ -167,7 +167,7 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// @@ -193,7 +193,7 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// @@ -217,7 +217,7 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// @@ -243,7 +243,7 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::TcpStream; /// @@ -268,7 +268,7 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use std::net::Shutdown; /// diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index 4588be12c..b5663871d 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -30,7 +30,7 @@ use crate::net::ToSocketAddrs; /// ## Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::UdpSocket; /// @@ -60,7 +60,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::UdpSocket; /// @@ -98,7 +98,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::UdpSocket; /// @@ -118,7 +118,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::UdpSocket; /// @@ -162,7 +162,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::UdpSocket; /// @@ -195,7 +195,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::UdpSocket; /// @@ -230,7 +230,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::UdpSocket; /// @@ -260,7 +260,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::net::UdpSocket; /// @@ -381,7 +381,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use std::net::Ipv4Addr; /// @@ -410,7 +410,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use std::net::{Ipv6Addr, SocketAddr}; /// diff --git a/src/os/unix/fs.rs b/src/os/unix/fs.rs index be8932c06..edf2f22d0 100644 --- a/src/os/unix/fs.rs +++ b/src/os/unix/fs.rs @@ -18,7 +18,7 @@ use crate::task::blocking; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::fs::symlink; /// diff --git a/src/os/unix/net/datagram.rs b/src/os/unix/net/datagram.rs index 1f971f7f5..943250584 100644 --- a/src/os/unix/net/datagram.rs +++ b/src/os/unix/net/datagram.rs @@ -29,7 +29,7 @@ use crate::task::blocking; /// ## Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -57,7 +57,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -76,7 +76,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -96,7 +96,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -123,7 +123,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -143,7 +143,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -165,7 +165,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -186,7 +186,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -211,7 +211,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -232,7 +232,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -256,7 +256,7 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// @@ -280,7 +280,7 @@ impl UnixDatagram { /// ## Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixDatagram; /// use std::net::Shutdown; diff --git a/src/os/unix/net/listener.rs b/src/os/unix/net/listener.rs index eba2fadc3..8c4d824e1 100644 --- a/src/os/unix/net/listener.rs +++ b/src/os/unix/net/listener.rs @@ -33,7 +33,7 @@ use crate::task::{blocking, Context, Poll}; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixListener; /// use async_std::prelude::*; @@ -58,7 +58,7 @@ impl UnixListener { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixListener; /// @@ -82,7 +82,7 @@ impl UnixListener { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixListener; /// @@ -128,7 +128,7 @@ impl UnixListener { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixListener; /// use async_std::prelude::*; @@ -152,7 +152,7 @@ impl UnixListener { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixListener; /// diff --git a/src/os/unix/net/stream.rs b/src/os/unix/net/stream.rs index ae30b5bf9..0cd48eb10 100644 --- a/src/os/unix/net/stream.rs +++ b/src/os/unix/net/stream.rs @@ -24,7 +24,7 @@ use crate::task::{blocking, Context, Poll}; /// # Examples /// /// ```no_run -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixStream; /// use async_std::prelude::*; @@ -47,7 +47,7 @@ impl UnixStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixStream; /// @@ -75,7 +75,7 @@ impl UnixStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixStream; /// @@ -99,7 +99,7 @@ impl UnixStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixStream; /// @@ -117,7 +117,7 @@ impl UnixStream { /// # Examples /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixStream; /// @@ -138,7 +138,7 @@ impl UnixStream { /// [`Shutdown`]: https://doc.rust-lang.org/std/net/enum.Shutdown.html /// /// ```no_run - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// # /// use async_std::os::unix::net::UnixStream; /// use std::net::Shutdown; diff --git a/src/stream/empty.rs b/src/stream/empty.rs index c9deea867..7ada3255a 100644 --- a/src/stream/empty.rs +++ b/src/stream/empty.rs @@ -9,7 +9,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::stream; diff --git a/src/stream/extend.rs b/src/stream/extend.rs index 27efd8b70..088f7a483 100644 --- a/src/stream/extend.rs +++ b/src/stream/extend.rs @@ -14,7 +14,7 @@ use crate::stream::IntoStream; /// ## Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::stream::{self, Extend}; diff --git a/src/stream/from_stream.rs b/src/stream/from_stream.rs index 047dab8fb..702acd873 100644 --- a/src/stream/from_stream.rs +++ b/src/stream/from_stream.rs @@ -14,7 +14,7 @@ use std::pin::Pin; /// Basic usage: /// /// ``` -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use crate::async_std::stream::FromStream; /// use async_std::prelude::*; /// use async_std::stream; @@ -30,7 +30,7 @@ use std::pin::Pin; /// Using `collect` to implicitly use `FromStream` /// ///``` -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use async_std::prelude::*; /// use async_std::stream; /// let five_fives = stream::repeat(5).take(5); @@ -87,7 +87,7 @@ use std::pin::Pin; /// } /// } /// -/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// // Now we can make a new stream... /// let stream = stream::repeat(5).take(5); /// @@ -116,7 +116,7 @@ pub trait FromStream { /// Basic usage: /// /// ``` - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # fn main() -> std::io::Result<()> { async_std::thread::spawn_task(async { /// use crate::async_std::stream::FromStream; /// use async_std::prelude::*; /// use async_std::stream; diff --git a/src/stream/mod.rs b/src/stream/mod.rs index 8aa12a2f1..bef44f697 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -7,7 +7,7 @@ //! # Examples //! //! ``` -//! # fn main() { async_std::task::block_on(async { +//! # fn main() { async_std::thread::spawn_task(async { //! # //! use async_std::prelude::*; //! use async_std::stream; diff --git a/src/stream/once.rs b/src/stream/once.rs index 133a155c9..b9d116c1a 100644 --- a/src/stream/once.rs +++ b/src/stream/once.rs @@ -8,7 +8,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::stream; diff --git a/src/stream/repeat.rs b/src/stream/repeat.rs index 1a6da4116..7277701a0 100644 --- a/src/stream/repeat.rs +++ b/src/stream/repeat.rs @@ -8,7 +8,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::prelude::*; /// use async_std::stream; diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index 8849605ca..aed18b315 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -7,7 +7,7 @@ //! # Examples //! //! ``` -//! # fn main() { async_std::task::block_on(async { +//! # fn main() { async_std::thread::spawn_task(async { //! # //! use async_std::prelude::*; //! use async_std::stream; @@ -132,7 +132,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::pin::Pin; @@ -185,7 +185,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::stream; @@ -211,7 +211,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::stream; @@ -247,7 +247,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -279,7 +279,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -316,7 +316,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -346,7 +346,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -380,7 +380,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -413,7 +413,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::stream; @@ -444,7 +444,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -476,7 +476,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -517,7 +517,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -556,7 +556,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -572,7 +572,7 @@ extension_trait! { Calling `nth()` multiple times: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -590,7 +590,7 @@ extension_trait! { ``` Returning `None` if the stream finished before returning `n` elements: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -633,7 +633,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::stream; @@ -648,7 +648,7 @@ extension_trait! { Empty stream: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::stream; @@ -684,7 +684,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -699,7 +699,7 @@ extension_trait! { Resuming after a first find: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -729,7 +729,7 @@ extension_trait! { Applies function to the elements of stream and returns the first non-none result. ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -762,7 +762,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -793,7 +793,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use std::collections::VecDeque; @@ -841,7 +841,7 @@ extension_trait! { Basic usage: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::stream; @@ -855,7 +855,7 @@ extension_trait! { Empty stream: ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::stream; @@ -900,7 +900,7 @@ extension_trait! { ## Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -941,7 +941,7 @@ extension_trait! { ## Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -971,7 +971,7 @@ extension_trait! { ## Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -999,7 +999,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; use std::sync::mpsc::channel; @@ -1057,7 +1057,7 @@ extension_trait! { ## Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use std::collections::VecDeque; @@ -1104,7 +1104,7 @@ extension_trait! { # Examples ``` - # fn main() { async_std::task::block_on(async { + # fn main() { async_std::thread::spawn_task(async { # use async_std::prelude::*; use async_std::stream; diff --git a/src/sync/barrier.rs b/src/sync/barrier.rs index 43488ee49..e3607607c 100644 --- a/src/sync/barrier.rs +++ b/src/sync/barrier.rs @@ -8,10 +8,10 @@ use crate::sync::Mutex; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::{Arc, Barrier}; -/// use async_std::task; +/// use async_std::thread; /// /// let mut handles = Vec::with_capacity(10); /// let barrier = Arc::new(Barrier::new(10)); @@ -118,10 +118,10 @@ impl Barrier { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::{Arc, Barrier}; - /// use async_std::task; + /// use async_std::thread; /// /// let mut handles = Vec::with_capacity(10); /// let barrier = Arc::new(Barrier::new(10)); @@ -188,7 +188,7 @@ impl BarrierWaitResult { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::Barrier; /// @@ -210,7 +210,7 @@ mod test { use futures_util::stream::StreamExt; use crate::sync::{Arc, Barrier}; - use crate::task; + use crate::thread; #[test] fn test_barrier() { @@ -219,7 +219,7 @@ mod test { // solid. for _ in 0..1_000 { - task::block_on(async move { + thread::spawn_task(async move { const N: usize = 10; let barrier = Arc::new(Barrier::new(N)); diff --git a/src/sync/mod.rs b/src/sync/mod.rs index df1d71ab3..5eab62584 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -9,7 +9,7 @@ //! Spawn a task that updates an integer protected by a mutex: //! //! ``` -//! # fn main() { async_std::task::block_on(async { +//! # fn main() { async_std::thread::spawn_task(async { //! # //! use std::sync::Arc; //! diff --git a/src/sync/mutex.rs b/src/sync/mutex.rs index 673eb8300..b5356be4d 100644 --- a/src/sync/mutex.rs +++ b/src/sync/mutex.rs @@ -24,12 +24,12 @@ const BLOCKED: usize = 1 << 1; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use std::sync::Arc; /// /// use async_std::sync::Mutex; -/// use async_std::task; +/// use async_std::thread; /// /// let m = Arc::new(Mutex::new(0)); /// let mut tasks = vec![]; @@ -82,12 +82,12 @@ impl Mutex { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use std::sync::Arc; /// /// use async_std::sync::Mutex; - /// use async_std::task; + /// use async_std::thread; /// /// let m1 = Arc::new(Mutex::new(10)); /// let m2 = m1.clone(); @@ -196,12 +196,12 @@ impl Mutex { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use std::sync::Arc; /// /// use async_std::sync::Mutex; - /// use async_std::task; + /// use async_std::thread; /// /// let m1 = Arc::new(Mutex::new(10)); /// let m2 = m1.clone(); @@ -249,7 +249,7 @@ impl Mutex { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::Mutex; /// diff --git a/src/sync/rwlock.rs b/src/sync/rwlock.rs index 55a29fc4a..e3264a7ea 100644 --- a/src/sync/rwlock.rs +++ b/src/sync/rwlock.rs @@ -33,7 +33,7 @@ const READ_COUNT_MASK: usize = !(ONE_READ - 1); /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::RwLock; /// @@ -89,7 +89,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::RwLock; /// @@ -211,7 +211,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::RwLock; /// @@ -253,7 +253,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::RwLock; /// @@ -374,7 +374,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::RwLock; /// @@ -431,7 +431,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # /// use async_std::sync::RwLock; /// diff --git a/src/task/mod.rs b/src/task/mod.rs index a14e5d521..eebaa3d35 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -10,7 +10,7 @@ //! Spawn a task and await its result: //! //! ``` -//! # fn main() { async_std::task::block_on(async { +//! # fn main() { async_std::thread::spawn_task(async { //! # //! use async_std::task; //! @@ -30,7 +30,6 @@ pub use std::task::{Context, Poll, Waker}; #[doc(inline)] pub use async_macros::ready; -pub use block_on::block_on; pub use builder::Builder; pub use pool::spawn; pub use sleep::sleep; @@ -38,16 +37,15 @@ pub use task::{JoinHandle, Task, TaskId}; pub use task_local::{AccessError, LocalKey}; pub use worker::current; -mod block_on; mod builder; mod pool; mod sleep; mod sleepers; -mod task; -mod task_local; -mod worker; pub(crate) mod blocking; +pub(crate) mod task; +pub(crate) mod task_local; +pub(crate) mod worker; /// Spawns a blocking task. /// @@ -55,18 +53,18 @@ pub(crate) mod blocking; /// is useful to prevent long-running synchronous operations from blocking the main futures /// executor. /// -/// See also: [`task::block_on`]. +/// See also: [`thread::spawn_task`]. /// -/// [`task::block_on`]: fn.block_on.html +/// [`thread::spawn_task`]: fn.block_on.html /// /// # Examples /// /// Basic usage: /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # -/// use async_std::task; +/// use async_std::thread; /// /// task::blocking(async { /// println!("long-running task here"); diff --git a/src/task/pool.rs b/src/task/pool.rs index 49fbfe490..9400ab714 100644 --- a/src/task/pool.rs +++ b/src/task/pool.rs @@ -22,9 +22,9 @@ use crate::utils::abort_on_panic; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # -/// use async_std::task; +/// use async_std::thread; /// /// let handle = task::spawn(async { /// 1 + 2 diff --git a/src/task/sleep.rs b/src/task/sleep.rs index 9db09ffe7..671b92219 100644 --- a/src/task/sleep.rs +++ b/src/task/sleep.rs @@ -14,11 +14,11 @@ use crate::io; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # /// use std::time::Duration; /// -/// use async_std::task; +/// use async_std::thread; /// /// task::sleep(Duration::from_secs(1)).await; /// # diff --git a/src/task/task.rs b/src/task/task.rs index ba808aa22..1341c5b9d 100644 --- a/src/task/task.rs +++ b/src/task/task.rs @@ -68,9 +68,9 @@ impl JoinHandle { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # fn main() { async_std::thread::spawn_task(async { /// # - /// use async_std::task; + /// use async_std::thread; /// /// let handle = task::spawn(async { /// 1 + 2 @@ -101,9 +101,9 @@ impl Future for JoinHandle { /// /// ``` /// # -/// use async_std::task; +/// use async_std::thread; /// -/// task::block_on(async { +/// thread::spawn_task(async { /// println!("id = {:?}", task::current().id()); /// }) /// ``` diff --git a/src/task/task_local.rs b/src/task/task_local.rs index 8347e34b6..7fa45bc69 100644 --- a/src/task/task_local.rs +++ b/src/task/task_local.rs @@ -25,14 +25,14 @@ use crate::utils::abort_on_panic; /// # /// use std::cell::Cell; /// -/// use async_std::task; +/// use async_std::thread; /// use async_std::prelude::*; /// /// task_local! { /// static VAL: Cell = Cell::new(5); /// } /// -/// task::block_on(async { +/// thread::spawn_task(async { /// let v = VAL.with(|c| c.get()); /// assert_eq!(v, 5); /// }); @@ -96,14 +96,14 @@ impl LocalKey { /// # /// use std::cell::Cell; /// - /// use async_std::task; + /// use async_std::thread; /// use async_std::prelude::*; /// /// task_local! { /// static NUMBER: Cell = Cell::new(5); /// } /// - /// task::block_on(async { + /// thread::spawn_task(async { /// let v = NUMBER.with(|c| c.get()); /// assert_eq!(v, 5); /// }); @@ -135,14 +135,14 @@ impl LocalKey { /// # /// use std::cell::Cell; /// - /// use async_std::task; + /// use async_std::thread; /// use async_std::prelude::*; /// /// task_local! { /// static VAL: Cell = Cell::new(5); /// } /// - /// task::block_on(async { + /// thread::spawn_task(async { /// let v = VAL.try_with(|c| c.get()); /// assert_eq!(v, Ok(5)); /// }); diff --git a/src/task/worker.rs b/src/task/worker.rs index fc2a6e7ef..4493ca3be 100644 --- a/src/task/worker.rs +++ b/src/task/worker.rs @@ -22,9 +22,9 @@ use crate::utils::abort_on_panic; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # fn main() { async_std::thread::spawn_task(async { /// # -/// use async_std::task; +/// use async_std::thread; /// /// println!("The name of this task is {:?}", task::current().name()); /// # diff --git a/src/thread/mod.rs b/src/thread/mod.rs new file mode 100644 index 000000000..7c8fdbc11 --- /dev/null +++ b/src/thread/mod.rs @@ -0,0 +1,12 @@ +//! Native threads. + +#[doc(inline)] +pub use std::thread::Result; +#[doc(inline)] +pub use std::thread::{current, panicking, park, park_timeout, sleep, spawn, yield_now}; +#[doc(inline)] +pub use std::thread::{AccessError, Builder, JoinHandle, LocalKey, Thread, ThreadId}; + +pub use spawn_task::spawn_task; + +mod spawn_task; diff --git a/src/task/block_on.rs b/src/thread/spawn_task.rs similarity index 92% rename from src/task/block_on.rs rename to src/thread/spawn_task.rs index 115040024..8e525dd7c 100644 --- a/src/task/block_on.rs +++ b/src/thread/spawn_task.rs @@ -6,10 +6,10 @@ use std::sync::Arc; use std::task::{RawWaker, RawWakerVTable}; use std::thread::{self, Thread}; -use super::task; -use super::task_local; -use super::worker; use crate::future::Future; +use crate::task::task; +use crate::task::task_local; +use crate::task::worker; use crate::task::{Context, Poll, Waker}; use kv_log_macro::trace; @@ -21,7 +21,7 @@ use kv_log_macro::trace; /// /// See also: [`task::blocking`]. /// -/// [`task::blocking`]: fn.blocking.html +/// [`task::blocking`]: ../task/fn.blocking.html /// /// [spawning]: https://doc.rust-lang.org/std/thread/fn.spawn.html /// [joining]: https://doc.rust-lang.org/std/thread/struct.JoinHandle.html#method.join @@ -29,17 +29,18 @@ use kv_log_macro::trace; /// # Examples /// /// ```no_run -/// use async_std::task; +/// use async_std::thread; /// /// fn main() { -/// task::block_on(async { +/// thread::spawn_task(async { /// println!("Hello, world!"); /// }) /// } /// ``` -pub fn block_on(future: F) -> T +pub fn spawn_task(future: F) -> T where F: Future, + T: Send, { unsafe { // A place on the stack where the result will be stored. @@ -60,11 +61,11 @@ where // Create a tag for the task. let tag = task::Tag::new(None); - // Log this `block_on` operation. + // Log this `spawn_task` operation. let child_id = tag.task_id().as_u64(); let parent_id = worker::get_task(|t| t.id().as_u64()).unwrap_or(0); - trace!("block_on", { + trace!("spawn_task", { parent_id: parent_id, child_id: child_id, }); @@ -74,7 +75,7 @@ where let future = async move { future.await; - trace!("block_on completed", { + trace!("spawn_task completed", { parent_id: parent_id, child_id: child_id, }); diff --git a/tests/addr.rs b/tests/addr.rs index aada557c3..208094d1d 100644 --- a/tests/addr.rs +++ b/tests/addr.rs @@ -1,14 +1,14 @@ use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; use async_std::net::ToSocketAddrs; -use async_std::task; +use async_std::thread; fn blocking_resolve(a: A) -> Result, String> where A: ToSocketAddrs, A::Iter: Send, { - let socket_addrs = task::block_on(a.to_socket_addrs()); + let socket_addrs = thread::spawn_task(a.to_socket_addrs()); match socket_addrs { Ok(a) => Ok(a.collect()), Err(e) => Err(e.to_string()), diff --git a/tests/io_timeout.rs b/tests/io_timeout.rs index 85a17ab75..4c4819d75 100644 --- a/tests/io_timeout.rs +++ b/tests/io_timeout.rs @@ -1,12 +1,12 @@ use std::time::Duration; use async_std::io; -use async_std::task; +use async_std::thread; #[test] #[should_panic(expected = "timed out")] fn io_timeout_timedout() { - task::block_on(async { + thread::spawn_task(async { io::timeout(Duration::from_secs(1), async { let stdin = io::stdin(); let mut line = String::new(); @@ -21,7 +21,7 @@ fn io_timeout_timedout() { #[test] #[should_panic(expected = "My custom error")] fn io_timeout_future_err() { - task::block_on(async { + thread::spawn_task(async { io::timeout(Duration::from_secs(1), async { Err::<(), io::Error>(io::Error::new(io::ErrorKind::Other, "My custom error")) }) @@ -32,7 +32,7 @@ fn io_timeout_future_err() { #[test] fn io_timeout_future_ok() { - task::block_on(async { + thread::spawn_task(async { io::timeout(Duration::from_secs(1), async { Ok(()) }) .await .unwrap(); // We shouldn't panic at all diff --git a/tests/mutex.rs b/tests/mutex.rs index fd1c07b38..1b67aedb3 100644 --- a/tests/mutex.rs +++ b/tests/mutex.rs @@ -3,11 +3,12 @@ use std::sync::Arc; use async_std::prelude::*; use async_std::sync::Mutex; use async_std::task; +use async_std::thread; use futures::channel::mpsc; #[test] fn smoke() { - task::block_on(async { + thread::spawn_task(async { let m = Mutex::new(()); drop(m.lock().await); drop(m.lock().await); @@ -35,7 +36,7 @@ fn get_mut() { #[test] fn contention() { - task::block_on(async { + thread::spawn_task(async { let (tx, mut rx) = mpsc::unbounded(); let tx = Arc::new(tx); diff --git a/tests/rwlock.rs b/tests/rwlock.rs index ff25e862d..3e4cf097f 100644 --- a/tests/rwlock.rs +++ b/tests/rwlock.rs @@ -8,6 +8,7 @@ use std::task::{Context, Poll}; use async_std::prelude::*; use async_std::sync::RwLock; use async_std::task; +use async_std::thread; use futures::channel::mpsc; /// Generates a random number in `0..n`. @@ -36,7 +37,7 @@ pub fn random(n: u32) -> u32 { #[test] fn smoke() { - task::block_on(async { + thread::spawn_task(async { let lock = RwLock::new(()); drop(lock.read().await); drop(lock.write().await); @@ -47,7 +48,7 @@ fn smoke() { #[test] fn try_write() { - task::block_on(async { + thread::spawn_task(async { let lock = RwLock::new(0isize); let read_guard = lock.read().await; assert!(lock.try_write().is_none()); @@ -116,7 +117,7 @@ fn contention() { }); } - task::block_on(async { + thread::spawn_task(async { for _ in 0..N { rx.next().await.unwrap(); } @@ -170,7 +171,7 @@ fn writer_and_readers() { })); } - task::block_on(async { + thread::spawn_task(async { // Wait for readers to pass their asserts. for r in readers { r.await; diff --git a/tests/block_on.rs b/tests/spawn_task.rs similarity index 65% rename from tests/block_on.rs rename to tests/spawn_task.rs index c422d0630..8de557c41 100644 --- a/tests/block_on.rs +++ b/tests/spawn_task.rs @@ -1,15 +1,15 @@ -use async_std::task; +use async_std::thread; #[test] fn smoke() { - let res = task::block_on(async { 1 + 2 }); + let res = thread::spawn_task(async { 1 + 2 }); assert_eq!(res, 3); } #[test] #[should_panic = "boom"] fn panic() { - task::block_on(async { + thread::spawn_task(async { // This panic should get propagated into the parent thread. panic!("boom"); }); diff --git a/tests/task_local.rs b/tests/task_local.rs index 813185c84..92facb89f 100644 --- a/tests/task_local.rs +++ b/tests/task_local.rs @@ -2,6 +2,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use async_std::task; use async_std::task_local; +use async_std::thread; #[test] fn drop_local() { @@ -26,7 +27,7 @@ fn drop_local() { let task = handle.task().clone(); // Wait for the task to finish and make sure its task-local has been dropped. - task::block_on(async { + thread::spawn_task(async { handle.await; assert!(DROP_LOCAL.load(Ordering::SeqCst)); drop(task); diff --git a/tests/tcp.rs b/tests/tcp.rs index c8281d713..dbb701229 100644 --- a/tests/tcp.rs +++ b/tests/tcp.rs @@ -2,6 +2,7 @@ use async_std::io; use async_std::net::{TcpListener, TcpStream}; use async_std::prelude::*; use async_std::task; +use async_std::thread; const THE_WINTERS_TALE: &[u8] = b" Each your doing, @@ -12,7 +13,7 @@ const THE_WINTERS_TALE: &[u8] = b" #[test] fn connect() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let listener = TcpListener::bind("127.0.0.1:0").await?; let addr = listener.local_addr()?; let t = task::spawn(async move { listener.accept().await }); @@ -29,7 +30,7 @@ fn connect() -> io::Result<()> { #[test] fn incoming_read() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let listener = TcpListener::bind("127.0.0.1:0").await?; let addr = listener.local_addr()?; diff --git a/tests/udp.rs b/tests/udp.rs index 319dc74ae..201bc4b3d 100644 --- a/tests/udp.rs +++ b/tests/udp.rs @@ -1,6 +1,6 @@ use async_std::io; use async_std::net::UdpSocket; -use async_std::task; +use async_std::thread; const THE_MERCHANT_OF_VENICE: &[u8] = b" If you prick us, do we not bleed? @@ -11,7 +11,7 @@ const THE_MERCHANT_OF_VENICE: &[u8] = b" #[test] fn send_recv() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let socket1 = UdpSocket::bind("127.0.0.1:0").await?; let socket2 = UdpSocket::bind("127.0.0.1:0").await?; diff --git a/tests/uds.rs b/tests/uds.rs index 3ab4d6ba4..0ed18930f 100644 --- a/tests/uds.rs +++ b/tests/uds.rs @@ -3,7 +3,7 @@ use async_std::io; use async_std::os::unix::net::{UnixDatagram, UnixListener, UnixStream}; use async_std::prelude::*; -use async_std::task; +use async_std::thread; use tempdir::TempDir; @@ -16,7 +16,7 @@ const JULIUS_CAESAR: &[u8] = b" #[test] fn send_recv() -> io::Result<()> { - task::block_on(async { + thread::spawn_task(async { let (socket1, socket2) = UnixDatagram::pair().unwrap(); socket1.send(JULIUS_CAESAR).await?; @@ -31,7 +31,7 @@ fn send_recv() -> io::Result<()> { #[test] fn into_raw_fd() -> io::Result<()> { use async_std::os::unix::io::{FromRawFd, IntoRawFd}; - task::block_on(async { + thread::spawn_task(async { let (socket1, socket2) = UnixDatagram::pair().unwrap(); socket1.send(JULIUS_CAESAR).await?; @@ -56,14 +56,14 @@ fn socket_ping_pong() { let iter_cnt = 16; let listener = - task::block_on(async { UnixListener::bind(&sock_path).await.expect("Socket bind") }); + thread::spawn_task(async { UnixListener::bind(&sock_path).await.expect("Socket bind") }); let server_handle = std::thread::spawn(move || { - task::block_on(async { ping_pong_server(listener, iter_cnt).await }).unwrap() + thread::spawn_task(async { ping_pong_server(listener, iter_cnt).await }).unwrap() }); let client_handle = std::thread::spawn(move || { - task::block_on(async { ping_pong_client(&sock_path, iter_cnt).await }).unwrap() + thread::spawn_task(async { ping_pong_client(&sock_path, iter_cnt).await }).unwrap() }); client_handle.join().unwrap();