blob: 10b5dfaff67b0b80af95b14d0fa2248b185fc210 [file] [log] [blame]
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion Future cancel()
/// Cancels the stream iterator (and the underlying stream subscription) early.
/// The stream iterator is automatically canceled if the moveNext future
/// completes with either false or an error.
/// If you need to stop listening for values before the stream iterator is
/// automatically closed, you must call cancel to ensure that the stream is
/// properly closed.
/// If moveNext has been called when the iterator is cancelled, its returned
/// future will complete with false as value, as will all further calls to
/// moveNext.
/// Returns a future if the cancel-operation is not completed synchronously.
/// Otherwise returns null.
/// @description Checks that call to cancel() makes subsequent call to moveNext()
/// complete with false as value.
/// @author kaigorodov
import "dart:async";
import "../../../Utils/expect.dart";
void check(List source, List expected) {
List actual = new List.empty(growable: true);
Stream stream = new Stream.fromIterable(source);
StreamIterator streamIterator = new StreamIterator(stream);
void step(bool hasNext) {
if (!hasNext) {
Expect.listEquals(expected, actual);
if (streamIterator.current == null) {
} else {
main() {
check([1, 2, 3, "end"], [1, 2, 3, "end"]);
check([1, 2, null, 3, "end"], [1, 2]);