Skip to content

Commit

Permalink
Use tokio mutex instead
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Aug 1, 2023
1 parent 98270bc commit ce95a6e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sdk/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl ClientBuilder {
sender: RwLock::new(mqtt_event_tx),
receiver: RwLock::new(mqtt_event_rx),
},
last_sync: std::sync::Mutex::new(None),
last_sync: tokio::sync::Mutex::new(None),
}),
};

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/client/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct ClientInner {
#[cfg(feature = "mqtt")]
pub(crate) mqtt: MqttInner,
#[cfg(target_family = "wasm")]
pub(crate) last_sync: std::sync::Mutex<Option<u32>>,
pub(crate) last_sync: tokio::sync::Mutex<Option<u32>>,
}

#[derive(Default)]
Expand Down Expand Up @@ -107,15 +107,15 @@ impl ClientInner {
#[cfg(target_family = "wasm")]
{
let current_time = crate::utils::unix_timestamp_now().as_secs() as u32;
if let Some(last_sync) = *self.last_sync.lock().unwrap() {
if let Some(last_sync) = *self.last_sync.lock().await {
if current_time < last_sync {
return Ok(self.network_info.read().await.clone());
}
}
let info = self.get_info().await?.node_info;
let mut client_network_info = self.network_info.write().await;
client_network_info.protocol_parameters = info.protocol.clone();
*self.last_sync.lock().unwrap() = Some(current_time + CACHE_NETWORK_INFO_TIMEOUT_IN_SECONDS);
*self.last_sync.lock().await = Some(current_time + CACHE_NETWORK_INFO_TIMEOUT_IN_SECONDS);
}

Ok(self.network_info.read().await.clone())
Expand Down

0 comments on commit ce95a6e

Please sign in to comment.