Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9370cd3

Browse files
committed
Fix README example
1 parent 34802ca commit 9370cd3

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ async fn get() -> io::Result<Vec<u8>> {
6666
let mut buf = vec![];
6767

6868
io::timeout(Duration::from_secs(5), async {
69-
stream.read_to_end(&mut buf).await?
69+
stream.read_to_end(&mut buf).await?;
7070
Ok(buf)
71-
})
71+
}).await
7272
}
7373

7474
fn main() {

‎examples/socket-timeouts.rs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::time::Duration;
2+
3+
use async_std::{
4+
prelude::*,
5+
task,
6+
io,
7+
net::TcpStream,
8+
};
9+
10+
async fn get() -> io::Result<Vec<u8>> {
11+
let mut stream = TcpStream::connect("example.com:80").await?;
12+
stream.write_all(b"GET /index.html HTTP/1.0\r\n\r\n").await?;
13+
14+
let mut buf = vec![];
15+
16+
io::timeout(Duration::from_secs(5), async {
17+
stream.read_to_end(&mut buf).await?;
18+
Ok(buf)
19+
}).await
20+
}
21+
22+
fn main() {
23+
task::block_on(async {
24+
let raw_response = get().await.expect("request");
25+
let response = String::from_utf8(raw_response)
26+
.expect("utf8 conversion");
27+
println!("received: {}", response);
28+
});
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /