transaction<R> method

  1. @override
Future<R> transaction<R>(
  1. Future<R> body(
    1. KeyStoreTxn<String, AtNotification, dynamic> txn
    )
)
override

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, AtNotification, dynamic> txn) body,
) async {
  final txn = _HiveAtNotificationKeystoreTxn(this);
  final R result;
  try {
    result = await body(txn);
  } catch (_) {
    rethrow;
  }
  for (final op in txn._ops.values) {
    await op.apply(this);
  }
  return result;
}