readNewValue method

FutureOr<T?> readNewValue({
  1. T? lastValue,
  2. Duration? interval,
  3. Duration? timeout,
  4. bool acceptsNullValue = true,
})

Reads a new value, different from lastValue, performing a pooling with interval (default: 10ms) and a timeout (default: 10s) that checks for a new value if needed.

Implementation

FutureOr<T?> readNewValue(
    {T? lastValue,
    Duration? interval,
    Duration? timeout,
    bool acceptsNullValue = true}) {
  var value = read();

  if (acceptsNullValue || value != null) {
    if (lastValue == null || value != lastValue) {
      return value;
    }
  }

  interval ??= Duration(milliseconds: 10);
  timeout ??= Duration(seconds: 10);
  return _readNewValueImpl(lastValue, interval, timeout, acceptsNullValue);
}