-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtokio.rs
61 lines (53 loc) · 1.68 KB
/
tokio.rs
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
// Copyright 2020, 2022 Cognite AS
//!
//! Set environment variables as per config.rs to run this.
//! It will query a feature called "default", report status for it, and upload a
//! metric bucket.
cfg_if::cfg_if! {
if #[cfg(feature = "reqwest")] {
use std::time::Duration;
use enum_map::Enum;
use futures_timer::Delay;
use serde::{Deserialize, Serialize};
use unleash_api_client::{client, config::EnvironmentConfig};
#[allow(non_camel_case_types)]
#[derive(Debug, Deserialize, Serialize, Enum, Clone)]
enum UserFeatures {
default,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let _ = simple_logger::SimpleLogger::new()
.with_utc_timestamps()
.init();
let config = EnvironmentConfig::from_env()?;
let client = client::ClientBuilder::default()
.interval(500)
.into_client::<UserFeatures, reqwest::Client>(
&config.api_url,
&config.app_name,
&config.instance_id,
config.secret,
)?;
client.register().await?;
futures::future::join(client.poll_for_updates(), async {
// Ensure we have features for this demo.
Delay::new(Duration::from_millis(500)).await;
println!(
"feature 'default' is {}",
client.is_enabled(UserFeatures::default, None, false)
);
// Wait to allow metrics upload
Delay::new(Duration::from_millis(500)).await;
// allow the future::join to finish
client.stop_poll().await;
})
.await;
Ok(())
}
} else {
fn main() -> Result<(), anyhow::Error> {
Err(anyhow::anyhow!("reqwest not enabled"))
}
}
}