-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtimeout.rs
More file actions
46 lines (39 loc) · 1.09 KB
/
timeout.rs
File metadata and controls
46 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use feignhttp::{feign, get, Feign};
#[get(url = "http://site_dne.com", connect_timeout = 3000)]
async fn connect_timeout() -> feignhttp::Result<String> {}
#[get(url = "https://httpbin.org/delay/5", timeout = 3000)]
async fn timeout() -> feignhttp::Result<String> {}
#[derive(Feign)]
struct Http;
#[feign(url = "http://site_dne.com", connect_timeout = 3000)]
impl Http {
#[get("", connect_timeout = 5000)] // 5000 will override 3000.
async fn get(&self) -> feignhttp::Result<String> {}
}
#[tokio::main]
async fn main() {
match connect_timeout().await {
Ok(res) => {
println!("connect_timeout: {}", res);
}
Err(err) => {
println!("connect_timeout: {:?}", err);
}
}
match timeout().await {
Ok(res) => {
println!("timeout: {}", res);
}
Err(err) => {
println!("timeout: {:?}", err);
}
}
match Http.get().await {
Ok(res) => {
println!("Http::get: {}", res);
}
Err(err) => {
println!("Http::get: {:?}", err);
}
}
}