-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtimeout.rs
More file actions
67 lines (58 loc) · 2.02 KB
/
timeout.rs
File metadata and controls
67 lines (58 loc) · 2.02 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use feignhttp::{FeignClientBuilder, feign, get};
/// The default connect_timeout is 10000 milliseconds.
#[get(url = "http://site_dne.com")]
async fn default_connect_timeout() -> feignhttp::Result<String> {}
/// The default timeout is 10000 milliseconds, override the default timeout.
#[get(url = "https://httpbin.org/delay/5", timeout = 3000)]
async fn default_timeout() -> feignhttp::Result<String> {}
/// The default timeout for all requests in the trait is 10000 milliseconds.
#[feign(url = "https://httpbin.org")]
pub trait TimeoutClient {
// The default timeout is 10000 milliseconds.
#[get(path = "/delay/5")]
async fn default_timeout(&self) -> feignhttp::Result<String>;
// Override the default timeout.
#[get(path = "/delay/5", timeout = 3000)]
async fn custom_timeout(&self) -> feignhttp::Result<String>;
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
match default_connect_timeout().await {
Ok(res) => {
println!("default_connect_timeout ok: {}", res);
}
Err(err) => {
// Execute here.
println!("default_connect_timeout err: {:?}", err);
}
}
match default_timeout().await {
Ok(res) => {
println!("default_timeout ok: {}", res);
}
Err(err) => {
// Execute here.
println!("default_timeout err: {:?}", err);
}
}
let http_client = TimeoutClient::builder().build()?;
match http_client.default_timeout().await {
Ok(res) => {
// Execute here.
println!("TimeoutClient.default_timeout ok: {}", res);
}
Err(err) => {
println!("TimeoutClient.default_timeout err: {:?}", err);
}
}
match http_client.custom_timeout().await {
Ok(res) => {
println!("TimeoutClient.custom_timeout ok: {}", res);
}
Err(err) => {
// Execute here.
println!("TimeoutClient.custom_timeout err: {:?}", err);
}
}
Ok(())
}