| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:async/async.dart'; | 7 import 'package:async/async.dart'; |
| 8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 test("stops emitting events for a stream that's removed", () async { | 500 test("stops emitting events for a stream that's removed", () async { |
| 501 var controller = new StreamController<String>(); | 501 var controller = new StreamController<String>(); |
| 502 streamGroup.add(controller.stream); | 502 streamGroup.add(controller.stream); |
| 503 | 503 |
| 504 expect(streamGroup.stream.toList(), completion(equals(["first"]))); | 504 expect(streamGroup.stream.toList(), completion(equals(["first"]))); |
| 505 | 505 |
| 506 controller.add("first"); | 506 controller.add("first"); |
| 507 await flushMicrotasks(); | 507 await flushMicrotasks(); |
| 508 controller.add("second"); | 508 controller.add("second"); |
| 509 | 509 |
| 510 expect(streamGroup.remove(controller.stream), isNull); | 510 expect(streamGroup.remove(controller.stream), completion(null)); |
| 511 expect(streamGroup.close(), completes); | 511 expect(streamGroup.close(), completes); |
| 512 }); | 512 }); |
| 513 | 513 |
| 514 test("is a no-op for an unknown stream", () { | 514 test("is a no-op for an unknown stream", () { |
| 515 var controller = new StreamController<String>(); | 515 var controller = new StreamController<String>(); |
| 516 expect(streamGroup.remove(controller.stream), isNull); | 516 expect(streamGroup.remove(controller.stream), isNull); |
| 517 }); | 517 }); |
| 518 | 518 |
| 519 test("and closed closes the group when the last stream is removed", | 519 test("and closed closes the group when the last stream is removed", |
| 520 () async { | 520 () async { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 541 test("doesn't emit events from a removed stream", () { | 541 test("doesn't emit events from a removed stream", () { |
| 542 var controller = new StreamController<String>(); | 542 var controller = new StreamController<String>(); |
| 543 streamGroup.add(controller.stream); | 543 streamGroup.add(controller.stream); |
| 544 | 544 |
| 545 // The subscription to [controller.stream] is canceled synchronously, so | 545 // The subscription to [controller.stream] is canceled synchronously, so |
| 546 // the first event is dropped even though it was added before the | 546 // the first event is dropped even though it was added before the |
| 547 // removal. This is documented in [StreamGroup.remove]. | 547 // removal. This is documented in [StreamGroup.remove]. |
| 548 expect(streamGroup.stream.toList(), completion(isEmpty)); | 548 expect(streamGroup.stream.toList(), completion(isEmpty)); |
| 549 | 549 |
| 550 controller.add("first"); | 550 controller.add("first"); |
| 551 expect(streamGroup.remove(controller.stream), isNull); | 551 expect(streamGroup.remove(controller.stream), completion(null)); |
| 552 controller.add("second"); | 552 controller.add("second"); |
| 553 | 553 |
| 554 expect(streamGroup.close(), completes); | 554 expect(streamGroup.close(), completes); |
| 555 }); | 555 }); |
| 556 | 556 |
| 557 test("cancels the stream's subscription", () async { | 557 test("cancels the stream's subscription", () async { |
| 558 var controller = new StreamController<String>(); | 558 var controller = new StreamController<String>(); |
| 559 streamGroup.add(controller.stream); | 559 streamGroup.add(controller.stream); |
| 560 | 560 |
| 561 streamGroup.stream.listen(null); | 561 streamGroup.stream.listen(null); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 controller.close(); | 712 controller.close(); |
| 713 | 713 |
| 714 await streamGroup.close(); | 714 await streamGroup.close(); |
| 715 expect(events, equals(["one", "two", "three", "four", "five", "six"])); | 715 expect(events, equals(["one", "two", "three", "four", "five", "six"])); |
| 716 }); | 716 }); |
| 717 }); | 717 }); |
| 718 } | 718 } |
| 719 | 719 |
| 720 /// Wait for all microtasks to complete. | 720 /// Wait for all microtasks to complete. |
| 721 Future flushMicrotasks() => new Future.delayed(Duration.ZERO); | 721 Future flushMicrotasks() => new Future.delayed(Duration.ZERO); |
| OLD | NEW |