Skip to content

Commit

Permalink
Use mutex prior to blocking on async for DB
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah authored and ermo committed Mar 3, 2024
1 parent fd984f0 commit 06807a7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions moss/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
//
// SPDX-License-Identifier: MPL-2.0

use std::{future::Future, sync::Arc};
use std::{
future::Future,
sync::{Arc, Mutex},
};

use sqlx::Sqlite;
use tokio::sync::Mutex;

use crate::runtime;

Expand All @@ -25,9 +27,8 @@ impl Pool {
where
F: Future<Output = T>,
{
runtime::block_on(async {
let pool = self.0.lock().await.clone();
f(pool).await
})
let _guard = self.0.lock().expect("mutex guard");
let pool = _guard.clone();
runtime::block_on(f(pool))
}
}

0 comments on commit 06807a7

Please sign in to comment.