transaction method

Future transaction(
  1. Future<void> work(
    1. Transaction transaction
    )
)
override

Functional way to execute a transaction. This method takes care of creating and releasing the transaction.

Implementation

Future<dynamic> transaction(Future<void> work(Transaction transaction)) async {
  Transaction trans = await Transaction.begin(this);
  try {
    await work(trans);
  } catch (e) {
    await trans.rollback();
    if (e is! RollbackError) rethrow;
    return e;
  }
  await trans.commit();
}