runEither<F, T> method

  1. @override
Future<Either<F, T>> runEither<F, T>({
  1. required Future<Either<F, T>> body(),
})
override

Runs body inside the store's transaction.

A Left result rolls the transaction back — its writes are undone — and the failure is handed straight back. A Right commits.

Implementation

@override
Future<Either<F, T>> runEither<F, T>({
  required Future<Either<F, T>> Function() body,
}) async {
  final snapshots = <InMemoryRowSource, Map<String, Map<String, dynamic>>>{
    for (final table in _tables) table: table.snapshot(),
  };
  final result = await body();
  if (result.isLeft()) {
    for (final entry in snapshots.entries) {
      entry.key.replaceAll(entry.value);
    }
  }
  return result;
}