-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.rs
46 lines (38 loc) · 1.39 KB
/
main.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
use enum_map::Enum;
use serde::{Deserialize, Serialize};
use std::env;
use dotenvy::dotenv;
use std::error::Error;
use std::time::Duration;
use tokio::time::sleep;
use unleash_api_client::client::ClientBuilder;
use unleash_api_client::Client;
#[derive(Debug, Deserialize, Serialize, Enum, Clone)]
enum Flags {
#[serde(rename = "example-flag")] // TODO: Flag name
TestFlag,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
dotenv().expect(".env file not found");
let api_url = env::var("UNLEASH_API_URL").expect("UNLEASH_API_URL not found");
let token = env::var("UNLEASH_API_TOKEN").expect("UNLEASH_API_TOKEN not found");
let client: Client<Flags, reqwest::Client> = ClientBuilder::default()
.interval(5000) // Polling & metrics interval - default 15000 (ms)
.into_client(
&api_url,
"codesandbox", // App name
"rust", // InstanceId
Some(token),
)?;
client.register().await?;
let (_, _) = tokio::join!(client.poll_for_updates(), async {
sleep(Duration::from_millis(1000)).await;
let is_enabled = client.is_enabled(Flags::TestFlag, None, true);
println!("\nIs flag enabled: {}\n", is_enabled);
sleep(Duration::from_millis(5000)).await;
client.stop_poll().await;
Ok::<(), Box<dyn Error + Send + Sync>>(())
});
Ok(())
}