run method

Future<R> run(
  1. Future<R> action(), {
  2. required String? debugName,
})

useTransaction is intended for debugging purposes. By setting useTransaction and db changes are visible as soon as the occur rather than only once the transaction completes. So this option allows you to inspect the db as updates occur.

Implementation

Future<R> run(Future<R> Function() action,
    {required String? debugName}) async {
  logger.finer(() => 'Start transaction($id db: ${db.id} '
      'isolate: ${Service.getIsolateID(Isolate.current)}): '
      'useTransaction: $useTransaction '
      'debugName: ${debugName ?? 'none'}');
  if (useTransaction) {
    /// run using a transaction
    final result = await db.transaction(() async => action());
    _commited = true;
    logger.finer(() =>
        'End transaction($id db: ${db.id}): useTransaction: $useTransaction '
        'debugName: ${debugName ?? 'none'}');
    return result;
  } else {
    // run without a transaction
    final result = await action();
    _commited = true;
    logger.finer(() =>
        'End transaction($id db: ${db.id}): useTransaction: $useTransaction '
        'debugName: ${debugName ?? 'none'}');
    return result;
  }
}