open method

FutureOr<Object?> open(
  1. FutureOr<Object> opener(),
  2. FutureOr<void> closer()?
)

Opens this transaction. This is called by the DBAdapter implementation.

Implementation

FutureOr<Object?> open(
    FutureOr<Object> Function() opener, FutureOr<void> Function()? closer) {
  if (_opening) {
    throw StateError("Transaction already opening:\n$this");
  } else if (_open) {
    throw StateError("Transaction already open:\n$this");
  }

  _initTime ??= DateTime.now();

  _addToAPIRequest();

  _opening = true;
  _transactionCloser = closer;

  return asyncTry(opener, then: (c) {
    _openImpl(c!);
    return c;
  }, onError: (e, s) {
    _logTransaction.severe("Error opening transaction:\n$this", e, s);
  });
}