Skip to content

Commit

Permalink
let hue initialize in background
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelLieb committed Mar 4, 2024
1 parent 18a2e85 commit b6aaf58
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ impl Config {
) -> Result<Vec<Box<dyn LightService + Send>>, LightServiceError> {
let mut lightservices: Vec<Box<dyn LightService + Send>> = Vec::new();

let mut handles = Vec::new();
for settings in &self.hue {
let settings = settings.clone();
let handle = tokio::spawn(async move {
hue::connect_with_settings(settings).await
});

handles.push(handle);
}

if let Some(path) = &self.serialize_onsets {
let path = if path.is_empty() { "onsets.cbor" } else { path };
let serializer = serialize::OnsetContainer::init(
Expand Down Expand Up @@ -175,9 +185,9 @@ impl Config {
}
}

for settings in &self.hue {
let bridge = hue::connect_with_settings(settings.clone()).await?;
lightservices.push(Box::new(bridge));
for handle in handles.into_iter() {
let bridge = handle.await.unwrap()?;
lightservices.push(Box::new(bridge))
}

Ok(lightservices)
Expand Down

0 comments on commit b6aaf58

Please sign in to comment.