DisposableFuture<T>.last constructor

DisposableFuture<T>.last(
  1. Stream<T> stream
)

Returns a disposable version of stream.last.

Implementation

factory DisposableFuture.last(Stream<T> stream) {
  final completer = Completer<T>.sync();
  StreamSubscription<Object?> subscription;
  T? lastValue;
  subscription = stream.listen((value) {
    lastValue = value;
  }, onDone: () {
    completer.complete(lastValue);
  });
  return DisposableFuture<T>(completer.future, subscription.cancel);
}