mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
async-await: streaming hyper body example (#656)
Add reading the hyper body in the async/await example.
This commit is contained in:
@@ -8,6 +8,7 @@ use tokio::prelude::*;
|
|||||||
use hyper::Client;
|
use hyper::Client;
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::str;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
tokio::run_async(async {
|
tokio::run_async(async {
|
||||||
@@ -21,5 +22,12 @@ pub fn main() {
|
|||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
println!("Response: {}", response.status());
|
println!("Response: {}", response.status());
|
||||||
|
|
||||||
|
let mut body = response.into_body();
|
||||||
|
|
||||||
|
while let Some(chunk) = await!(body.next()) {
|
||||||
|
let chunk = chunk.unwrap();
|
||||||
|
println!("chunk = {}", str::from_utf8(&chunk[..]).unwrap());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user