update method

  1. @visibleForTesting
  2. @protected
FutureOr<T?> update(
  1. FutureOr<T> updater(
    1. T old
    ), {
  2. dynamic onError(
    1. Object e,
    2. StackTrace s
    )?,
  3. int slowlyMs = 100,
  4. Object? debounceTag,
  5. Object? throttleTag,
  6. Object? mutexTag,
  7. dynamic ignoreSkipError = true,
})

updater if return value, will call put if return null, will not call put/putError onError if set null,will call putError if set function value, will not call putError, you can invoke putError manually slowlyMs if set <=0 value, will ignore debounce/throttleTag debounceTag enable debounce, require unique within the VM scope throttleTag enable throttle, require unique within the VM scope mutexTag enable concurrency lock (Exhaustive behavior), if the previous update with the same mutexTag is still running, the current update will be ignored. ignoreSkipError ref runCatching.ignoreSkipError

Implementation

@visibleForTesting
@protected
FutureOr<T?> update(
  FutureOr<T> Function(T old) updater, {
  Function(Object e, StackTrace s)? onError,
  int slowlyMs = 100,
  Object? debounceTag,
  Object? throttleTag,
  Object? mutexTag,
  ignoreSkipError = true,
}) => runCatching<T>(
  () => updater(value),
  onSuccess: (r) => put(r),
  onFailure: (e, s) => (onError ?? putError).call(e, s),
  ignoreSkipError: ignoreSkipError,
  slowlyMs: slowlyMs,
  debounceTag: debounceTag,
  throttleTag: throttleTag,
  mutexTag: mutexTag,
);