untilValue<U> method

Future<void> untilValue<U>(
  1. U value
)

Returns a Future that completes when the value of this cell equals value.

If the value of this cell is already equal to value, the Future completes immediately.

NOTE: An observer is added to this cell, and only removed when the cell's value equals value. If this never happens, the observer is never removed.

Implementation

Future<void> untilValue<U>(U value) async {
  final completer = Completer();

  final watcher = ValueCell.watch(() {
    try {
      if (!completer.isCompleted && this() == value) {
        completer.complete();
      }
    }
    catch (e) {
      // Prevent error from being printed to console
    }
  });

  await completer.future;
  watcher.stop();
}