OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "dart:async"; |
| 6 import "package:expect/expect.dart"; |
| 7 import "package:async_helper/async_helper.dart"; |
| 8 |
| 9 Stream timedStream(int n) { |
| 10 int i = 0; |
| 11 StreamController controller; |
| 12 tick() { |
| 13 if (i >= n) { |
| 14 controller.close(); |
| 15 return; |
| 16 } |
| 17 controller.add(i); |
| 18 i++; |
| 19 new Future.delayed(new Duration(milliseconds: 0), tick); |
| 20 } |
| 21 controller = new StreamController(onListen: tick); |
| 22 return controller.stream; |
| 23 } |
| 24 |
| 25 void main() { |
| 26 asyncStart(); |
| 27 StreamIterator iterator = new StreamIterator(timedStream(10)); |
| 28 helper(more) { |
| 29 if (!more) { |
| 30 // Canceling the already closed iterator should not lead to a crash. |
| 31 iterator.cancel(); |
| 32 asyncEnd(); |
| 33 } else { |
| 34 iterator.moveNext().then(helper); |
| 35 } |
| 36 } |
| 37 iterator.moveNext().then(helper); |
| 38 } |
OLD | NEW |