Skip to content

Commit

Permalink
fix: Update environment on client init
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Apr 4, 2024
1 parent c2ab95c commit 1f338a2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/flagsmith/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ impl Flagsmith {
flagsmith.options.environment_refresh_interval_mills;

if flagsmith.options.enable_local_evaluation {
// Update environment once...
update_environment(&client, &ds, &environment_url).unwrap();

// ...and continue updating in the background
let ds = Arc::clone(&ds);
thread::spawn(move || loop {
match rx.try_recv() {
Expand All @@ -152,10 +156,8 @@ impl Flagsmith {
}
Err(TryRecvError::Empty) => {}
}

update_environment(&client, &ds, &environment_url).unwrap();

thread::sleep(Duration::from_millis(environment_refresh_interval_mills));
update_environment(&client, &ds, &environment_url).unwrap();
});
}
return flagsmith;
Expand Down Expand Up @@ -581,7 +583,6 @@ mod tests {

// When
let mut _flagsmith = Flagsmith::new(environment_key.to_string(), flagsmith_options);
thread::sleep(std::time::Duration::from_millis(250));

// Then
let flags = _flagsmith.get_environment_flags();
Expand Down

0 comments on commit 1f338a2

Please sign in to comment.