Skip to content

Commit 946f2d3

Browse files
jkczyzclaude
andcommitted
Drop the DataStore::mutate_async wrapper
It only forwarded to mutate_with, so that method is now pub(crate) and the callers that await fallible reads use it directly. Written with the help of an AI tool. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 49950d9 commit 946f2d3

2 files changed

Lines changed: 10 additions & 18 deletions

File tree

‎src/data_store.rs‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,12 @@ where
451451
self.mutate_with(id, |current| async move { Ok(f(current.as_ref())) }).await
452452
}
453453

454-
async fn mutate_with<F, Fut>(&self, id: &SO::Id, f: F) -> Result<Option<SO>, Error>
454+
/// Like [`Self::mutate`], but allows the transformation to await fallible reads.
455+
///
456+
/// The mutation lock remains held while `f` runs. This is useful when the new state must be
457+
/// decided from an async read of another store without letting a concurrent writer invalidate
458+
/// that decision. Callers must keep cross-store lock ordering consistent to avoid deadlocks.
459+
pub(crate) async fn mutate_with<F, Fut>(&self, id: &SO::Id, f: F) -> Result<Option<SO>, Error>
455460
where
456461
F: FnOnce(Option<SO>) -> Fut,
457462
Fut: Future<Output = Result<Option<SO>, Error>>,
@@ -470,19 +475,6 @@ where
470475
Ok(Some(new_object))
471476
}
472477

473-
/// Like [`Self::mutate`], but allows the transformation to await fallible reads.
474-
///
475-
/// The mutation lock remains held while `f` runs. This is useful when the new state must be
476-
/// decided from an async read of another store without letting a concurrent writer invalidate
477-
/// that decision. Callers must keep cross-store lock ordering consistent to avoid deadlocks.
478-
pub(crate) async fn mutate_async<F, Fut>(&self, id: &SO::Id, f: F) -> Result<Option<SO>, Error>
479-
where
480-
F: FnOnce(Option<SO>) -> Fut,
481-
Fut: Future<Output = Result<Option<SO>, Error>>,
482-
{
483-
self.mutate_with(id, f).await
484-
}
485-
486478
/// Returns whether an object is stored under `id`.
487479
pub(crate) async fn contains_key(&self, id: &SO::Id) -> Result<bool, Error> {
488480
let _guard = self.mutation_lock.read().await;
@@ -1260,7 +1252,7 @@ mod tests {
12601252
}
12611253

12621254
#[tokio::test]
1263-
async fn mutate_async_awaits_fallible_reads() {
1255+
async fn mutate_with_awaits_fallible_reads() {
12641256
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
12651257
let logger = Arc::new(TestLogger::new());
12661258
let id = TestObjectId { id: [42u8; 4] };
@@ -1285,7 +1277,7 @@ mod tests {
12851277
);
12861278

12871279
let result = data_store
1288-
.mutate_async(&id, |existing| async move {
1280+
.mutate_with(&id, |existing| async move {
12891281
let mut updated = existing.unwrap();
12901282
updated.data = other_store.get(&other_id).await?.unwrap().data;
12911283
Ok(Some(updated))

‎src/wallet/payment_stores.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ impl PaymentStoresGuard<'_> {
176176
}
177177

178178
/// [`Self::mutate_pending_payment`] with a transformation that awaits fallible reads; see
179-
/// [`DataStore::mutate_async`](crate::data_store::DataStore::mutate_async).
179+
/// [`DataStore::mutate_with`](crate::data_store::DataStore::mutate_with).
180180
pub(super) async fn mutate_pending_payment_async<F, Fut>(
181181
&self, id: &PaymentId, f: F,
182182
) -> Result<Option<PendingPaymentDetails>, Error>
183183
where
184184
F: FnOnce(Option<PendingPaymentDetails>) -> Fut,
185185
Fut: Future<Output = Result<Option<PendingPaymentDetails>, Error>>,
186186
{
187-
self.stores.pending_payment_store.mutate_async(id, f).await
187+
self.stores.pending_payment_store.mutate_with(id, f).await
188188
}
189189
}

0 commit comments

Comments
 (0)