adjust method

Future<T?> adjust(
  1. AdjustFunc f
)

Reads an existing value, computes a new one with AdjustFunc and writes the new value to the storage.

Implementation

Future<T?> adjust(AdjustFunc f) async {
  if (this.isDisposed) return null;

  var oldVal = await this.read();

  if (this.isDisposed) return null;

  var newVal = f(oldVal);
  await this.write(newVal);

  if (this.isDisposed) return null;

  return newVal;
}