W3cubDocs

/Dart 2

isEmpty property

Future<bool> isEmpty

Whether this stream contains any elements.

Waits for the first element of this stream, then completes the returned future with true. If the stream ends without emitting any elements, the returned future is completed with false.

If the first event is an error, the returned future is completed with that error.

This operation listens to the stream, and a non-broadcast stream cannot be reused after checking whether it is empty.

Implementation

Future<bool> get isEmpty {
  _Future<bool> future = new _Future<bool>();
  StreamSubscription subscription;
  subscription = this.listen(
      (_) {
        _cancelAndValue(subscription, future, false);
      },
      onError: future._completeError,
      onDone: () {
        future._complete(true);
      },
      cancelOnError: true);
  return future;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-async/Stream/isEmpty.html