Skip to content

Commit

Permalink
Merge branch 'feature/async' of github.com:BlackbirdHQ/rustot into fi…
Browse files Browse the repository at this point in the history
…x/ensure_one_sub_on_topic
  • Loading branch information
KennethKnudsen97 committed Sep 26, 2024
2 parents c8d6a07 + 1763f6c commit 51e8c61
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/shadows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ where
}
}

pub async fn delete_shadow(&mut self) -> Result<(), Error> {
pub async fn delete_shadow(&self) -> Result<(), Error> {
let _delete_request = self.delete_requested.lock().await;

// Wait for mqtt to connect
Expand Down Expand Up @@ -460,7 +460,7 @@ where
}

/// Get an immutable reference to the internal local state.
pub async fn try_get(&mut self) -> Result<S, Error> {
pub async fn try_get(&self) -> Result<S, Error> {
self.dao.lock().await.read().await
}

Expand All @@ -481,6 +481,14 @@ where
Ok(state)
}

/// Report the state of the shadow.
pub async fn report(&self) -> Result<(), Error> {
let state = self.dao.lock().await.read().await?;

self.handler.report(&state).await?;
Ok(())
}

/// Update the state of the shadow.
///
/// This function will update the desired state of the shadow in the cloud,
Expand All @@ -507,7 +515,7 @@ where
Ok(())
}

pub async fn delete_shadow(&mut self) -> Result<(), Error> {
pub async fn delete_shadow(&self) -> Result<(), Error> {
self.handler.delete_shadow().await?;
self.dao.lock().await.write(&S::default()).await?;
Ok(())
Expand Down

0 comments on commit 51e8c61

Please sign in to comment.