write<T> method

T write<T>(
  1. T writeCallback()
)

Synchronously calls the provided callback inside a write transaction.

If no exception is thrown from within the callback, the transaction will be committed. It is more efficient to update several properties or even create multiple objects in a single write transaction.

Implementation

T write<T>(T Function() writeCallback) {
  final transaction = beginWrite();

  try {
    T result = writeCallback();
    transaction.commit();
    return result;
  } catch (e) {
    transaction.rollback();
    rethrow;
  }
}