forked from mirror/async-std
fix test code
This commit is contained in:
parent
b95bd6c1fe
commit
ec4b09ecd0
5 changed files with 20 additions and 16 deletions
|
@ -1,10 +1,12 @@
|
|||
use futures::select;
|
||||
use futures::FutureExt;
|
||||
use std::io::{self, BufReader as StdBufReader, BufRead};
|
||||
|
||||
use async_std::{
|
||||
io::{stdin, BufReader},
|
||||
io::{BufReader},
|
||||
net::{TcpStream, ToSocketAddrs},
|
||||
prelude::*,
|
||||
stream,
|
||||
task,
|
||||
};
|
||||
|
||||
|
@ -20,8 +22,9 @@ async fn try_main(addr: impl ToSocketAddrs) -> Result<()> {
|
|||
let reader = BufReader::new(reader);
|
||||
let mut lines_from_server = futures::StreamExt::fuse(reader.lines());
|
||||
|
||||
let stdin = BufReader::new(stdin());
|
||||
let mut lines_from_stdin = futures::StreamExt::fuse(stdin.lines());
|
||||
let stdin = StdBufReader::new(io::stdin());
|
||||
let mut lines_from_stdin = stream::from_iter(stdin.lines());
|
||||
|
||||
loop {
|
||||
select! {
|
||||
line = lines_from_server.next().fuse() => match line {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Prints a file given as an argument to stdout.
|
||||
|
||||
use std::env::args;
|
||||
use std::io::Write;
|
||||
|
||||
use async_std::fs::File;
|
||||
use async_std::io;
|
||||
|
@ -14,7 +15,7 @@ fn main() -> io::Result<()> {
|
|||
|
||||
task::block_on(async {
|
||||
let mut file = File::open(&path).await?;
|
||||
let mut stdout = io::stdout();
|
||||
let mut stdout = std::io::stdout();
|
||||
let mut buf = vec![0u8; LEN];
|
||||
|
||||
loop {
|
||||
|
@ -23,12 +24,12 @@ fn main() -> io::Result<()> {
|
|||
|
||||
// If this is the end of file, clean up and return.
|
||||
if n == 0 {
|
||||
stdout.flush().await?;
|
||||
stdout.flush()?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Write the buffer into stdout.
|
||||
stdout.write_all(&buf[..n]).await?;
|
||||
stdout.write_all(&buf[..n])?;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
//! Echoes lines read on stdin to stdout.
|
||||
|
||||
use std::io::Write;
|
||||
use async_std::io;
|
||||
use async_std::prelude::*;
|
||||
use async_std::task;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
task::block_on(async {
|
||||
let stdin = io::stdin();
|
||||
let mut stdout = io::stdout();
|
||||
let stdin = std::io::stdin();
|
||||
let mut stdout = std::io::stdout();
|
||||
let mut line = String::new();
|
||||
|
||||
loop {
|
||||
// Read a line from stdin.
|
||||
let n = stdin.read_line(&mut line).await?;
|
||||
let n = stdin.read_line(&mut line)?;
|
||||
|
||||
// If this is the end of stdin, return.
|
||||
if n == 0 {
|
||||
|
@ -20,8 +20,8 @@ fn main() -> io::Result<()> {
|
|||
}
|
||||
|
||||
// Write the line to stdout.
|
||||
stdout.write_all(line.as_bytes()).await?;
|
||||
stdout.flush().await?;
|
||||
stdout.write_all(line.as_bytes())?;
|
||||
stdout.flush()?;
|
||||
line.clear();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -8,11 +8,11 @@ use async_std::task;
|
|||
fn main() -> io::Result<()> {
|
||||
// This async scope times out after 5 seconds.
|
||||
task::block_on(io::timeout(Duration::from_secs(5), async {
|
||||
let stdin = io::stdin();
|
||||
let stdin = std::io::stdin();
|
||||
|
||||
// Read a line from the standard input and display it.
|
||||
let mut line = String::new();
|
||||
stdin.read_line(&mut line).await?;
|
||||
stdin.read_line(&mut line)?;
|
||||
dbg!(line);
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -8,9 +8,9 @@ use async_std::task;
|
|||
fn io_timeout_timedout() {
|
||||
task::block_on(async {
|
||||
io::timeout(Duration::from_secs(1), async {
|
||||
let stdin = io::stdin();
|
||||
let stdin = std::io::stdin();
|
||||
let mut line = String::new();
|
||||
let _n = stdin.read_line(&mut line).await?;
|
||||
let _n = stdin.read_line(&mut line)?;
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
|
|
Loading…
Reference in a new issue