appendBatch method

Future<int> appendBatch(
  1. List<WalBinRecord Function(int lsn, int prevLsn)> builders
)

Implementation

Future<int> appendBatch(
    List<WalBinRecord Function(int lsn, int prevLsn)> builders) async {
  if (_closed) throw StateError('WAL is closed');
  int lastLsn = _lsn;
  for (final builder in builders) {
    _lsn++;
    final prevLsn = _txnLastLsn[_currentTxnId] ?? 0;
    final record  = builder(_lsn, prevLsn);
    final encoded = record.encode();
    await _writeFramed(encoded);
    _txnLastLsn[record.txnId] = _lsn;
    lastLsn = _lsn;
  }
  await _flush();
  _flushedLsn = lastLsn;
  return lastLsn;
}