mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
26 lines
513 B
Rust
26 lines
513 B
Rust
#![feature(await_macro, async_await, futures_api)]
|
|||
|
|
|
||
|
|
#[macro_use]
|
||
|
|
extern crate tokio;
|
||
|
|
extern crate hyper;
|
||
|
|
|
||
|
|
use tokio::prelude::*;
|
||
|
|
use hyper::Client;
|
||
|
|
|
||
|
|
use std::time::Duration;
|
||
|
|
|
||
|
|
pub fn main() {
|
||
|
|
tokio::run_async(async {
|
||
|
|
let client = Client::new();
|
||
|
|
|
||
|
|
let uri = "http://httpbin.org/ip".parse().unwrap();
|
||
|
|
|
||
|
|
let response = await!({
|
||
|
|
client.get(uri)
|
||
|
|
.timeout(Duration::from_secs(10))
|
||
|
|
}).unwrap();
|
||
|
|
|
||
|
|
println!("Response: {}", response.status());
|
||
|
|
});
|
||
|
|
}
|