runInTransactionAsync<R, P> method
Like runAsync, but executes callback
within a read or write
transaction depending on mode
.
See the documentation on runAsync for important usage details.
The following example gets the name of a User object, deletes the object and returns the name within a write transaction:
String? readNameAndRemove(Store store, int objectId) {
var box = store.box<User>();
final nameOrNull = box.get(objectId)?.name;
box.remove(objectId);
return nameOrNull;
}
await store.runInTransactionAsync(TxMode.write, readNameAndRemove, objectId);
Implementation
Future<R> runInTransactionAsync<R, P>(
TxMode mode, TxAsyncCallback<R, P> callback, P param) =>
runAsync(
(Store store, P p) =>
store.runInTransaction(mode, () => callback(store, p)),
param);