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 // Test empty stream. |
| 6 import "package:expect/expect.dart"; |
| 7 import "dart:async"; |
| 8 import 'package:async_helper/async_helper.dart'; |
| 9 |
| 10 main() async { |
| 11 unreachable([a,b]) { throw "UNREACHABLE"; } |
| 12 int tick = 0; |
| 13 ticker() { tick++; } |
| 14 |
| 15 asyncStart(); |
| 16 |
| 17 Stream<int> s = const Stream<int>.empty(); // Is const constructor. |
| 18 Expect.isFalse(s is Stream<String>); // Respects type parameter. |
| 19 StreamSubscription<int> sub = |
| 20 s.listen(unreachable, onError: unreachable, onDone: ticker); |
| 21 Expect.isFalse(sub is StreamSubscription<String>); // Type parameter in sub. |
| 22 |
| 23 // Doesn't do callback in response to listen. |
| 24 Expect.equals(tick, 0); |
| 25 await flushMicrotasks(); |
| 26 // Completes eventually. |
| 27 Expect.equals(tick, 1); |
| 28 |
| 29 // It's a broadcast stream - can listen twice. |
| 30 Expect.isTrue(s.isBroadcast); |
| 31 StreamSubscription<int> sub2 = |
| 32 s.listen(unreachable, onError: unreachable, onDone: unreachable); |
| 33 // respects pause. |
| 34 sub2.pause(); |
| 35 await flushMicrotasks(); |
| 36 // respects cancel. |
| 37 sub2.cancel(); |
| 38 await flushMicrotasks(); |
| 39 Expect.equals(tick, 1); |
| 40 // Still not complete. |
| 41 |
| 42 StreamSubscription<int> sub3 = |
| 43 s.listen(unreachable, onError: unreachable, onDone: ticker); |
| 44 // respects pause. |
| 45 sub3.pause(); |
| 46 Expect.equals(tick, 1); |
| 47 await flushMicrotasks(); |
| 48 // Doesn't complete while paused. |
| 49 Expect.equals(tick, 1); |
| 50 sub3.resume(); |
| 51 await flushMicrotasks(); |
| 52 // Now completed. |
| 53 Expect.equals(tick, 2); |
| 54 |
| 55 asyncEnd(); |
| 56 } |
| 57 |
| 58 Future flushMicrotasks() => new Future.delayed(Duration.ZERO); |
OLD | NEW |