Skip to content

Commit

Permalink
use lock to prevent race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Lyaruu authored and SachaMorard committed Sep 23, 2024
1 parent 037cd54 commit b565181
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/config/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::Deserialize;
use std::collections::{HashMap, HashSet};
use std::path::Path;
use tokio::sync::OnceCell;
use std::sync::OnceLock;

static CONFIG: OnceCell<StaticConfiguration> = OnceCell::const_new();
static CONFIG: OnceLock<StaticConfiguration> = OnceLock::new();

pub trait Validate {
fn validate(&self) -> Result<(), Vec<String>>;
Expand Down Expand Up @@ -249,7 +249,5 @@ pub fn init_test_config() {
components: ComponentsConfiguration::default(),
};

if CONFIG.get().is_none() {
CONFIG.set(config).expect("Should initialize config");
}
CONFIG.get_or_init(|| config);
}

0 comments on commit b565181

Please sign in to comment.