| 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 sumStream(s) async { |
| 10 int accum = 0; |
| 11 await for (var v in s) { |
| 12 accum += v; |
| 13 } |
| 14 return accum; |
| 15 } |
| 16 |
| 17 test() async { |
| 18 var countStreamController; |
| 19 int i = 0; |
| 20 void tick() { |
| 21 if (i < 10) { |
| 22 countStreamController.add(i); |
| 23 i++; |
| 24 scheduleMicrotask(tick); |
| 25 } else { |
| 26 countStreamController.close(); |
| 27 } |
| 28 } |
| 29 |
| 30 countStreamController = new StreamController( |
| 31 onListen: () { |
| 32 scheduleMicrotask(tick); |
| 33 }); |
| 34 Expect.equals(45, await sumStream(countStreamController.stream)); |
| 35 } |
| 36 |
| 37 void main() { |
| 38 asyncStart(); |
| 39 test().then((_) => asyncEnd()); |
| 40 } |
| OLD | NEW |