debugging; box pinning (#101)

This commit is contained in:
Wyatt Verchere
2023-04-28 10:45:51 -07:00
committed by GitHub
parent dcca0ef474
commit 713a915161
5 changed files with 101 additions and 47 deletions

View File

@@ -138,34 +138,35 @@ impl State {
#[tracing::instrument]
/// Synchronize in-memory state with persistent state
pub async fn sync() -> crate::Result<()> {
let state = Self::get().await?;
Box::pin(async move {
let state = Self::get().await?;
let sync_settings = async {
let state = Arc::clone(&state);
let sync_settings = async {
let state = Arc::clone(&state);
tokio::spawn(async move {
let reader = state.settings.read().await;
reader.sync(&state.directories.settings_file()).await?;
Ok::<_, crate::Error>(())
})
.await?
};
tokio::spawn(async move {
let reader = state.settings.read().await;
reader.sync(&state.directories.settings_file()).await?;
Ok::<_, crate::Error>(())
})
.await?
};
let sync_profiles = async {
let state = Arc::clone(&state);
let sync_profiles = async {
let state = Arc::clone(&state);
tokio::spawn(async move {
let profiles = state.profiles.read().await;
tokio::spawn(async move {
let profiles = state.profiles.read().await;
profiles.sync().await?;
Ok::<_, crate::Error>(())
})
.await?
};
profiles.sync().await?;
Ok::<_, crate::Error>(())
})
.await?
};
tokio::try_join!(sync_settings, sync_profiles)?;
Ok(())
tokio::try_join!(sync_settings, sync_profiles)?;
Ok(())
})
.await
}
/// Reset semaphores to default values