transaction<R> method
Run body as a transaction. Mutations performed via the
supplied handle are buffered in memory and applied in body
order on successful completion; if the body throws, the
buffer is dropped and the exception propagates.
Hive impls provide best-effort atomicity; a future SQL impl will provide true atomicity.
Implementation
@override
Future<R> transaction<R>(
Future<R> Function(KeyStoreTxn<String, AtData, AtMetaData?> txn) body,
) async {
final txn = _HiveAtKeyValueStoreTxn(this);
final R result;
try {
result = await body(txn);
} catch (_) {
// body threw — drop buffered ops, propagate.
rethrow;
}
// Body succeeded — apply buffered ops in insertion order. Each
// applied op fires its own `changes` event via the standard
// putAll / remove paths.
for (final entry in txn._ops.values) {
await entry.apply(this);
}
return result;
}