Skip to content

Commit 2e7b564

Browse files
committed
libsql: move sync behind a async mutex
1 parent b80f611 commit 2e7b564

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libsql/src/local/database.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Database {
3333
#[cfg(feature = "replication")]
3434
pub replication_ctx: Option<ReplicationContext>,
3535
#[cfg(feature = "sync")]
36-
pub sync_ctx: Option<SyncContext>,
36+
pub sync_ctx: Option<tokio::sync::Mutex<SyncContext>>,
3737
}
3838

3939
impl Database {
@@ -143,7 +143,10 @@ impl Database {
143143
endpoint
144144
};
145145
let mut db = Database::open(&db_path, flags)?;
146-
db.sync_ctx = Some(SyncContext::new(endpoint, Some(auth_token)));
146+
db.sync_ctx = Some(tokio::sync::Mutex::new(SyncContext::new(
147+
endpoint,
148+
Some(auth_token),
149+
)));
147150
Ok(db)
148151
}
149152

@@ -383,7 +386,7 @@ impl Database {
383386
#[cfg(feature = "sync")]
384387
/// Push WAL frames to remote.
385388
pub async fn push(&self) -> Result<crate::database::Replicated> {
386-
let sync_ctx = self.sync_ctx.as_ref().unwrap();
389+
let sync_ctx = self.sync_ctx.as_ref().unwrap().lock().await;
387390
let conn = self.connect()?;
388391

389392
let page_size = {

0 commit comments

Comments
 (0)