Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: test/single_subscription_transformer_test.dart

Issue 1584023002: Add SingleSubscriptionTransformer. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Update pubspec Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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
7 import 'package:async/async.dart';
8 import 'package:test/test.dart';
9
10 import 'utils.dart';
11
12 void main() {
13 test("buffers events as soon as it's bound", () async {
14 var controller = new StreamController.broadcast();
15 var stream = controller.stream.transform(
16 const SingleSubscriptionTransformer());
17
18 // Add events before [stream] has a listener to be sure it buffers them.
19 controller.add(1);
20 controller.add(2);
21 await flushMicrotasks();
22
23 expect(stream.toList(), completion(equals([1, 2, 3, 4])));
24 await flushMicrotasks();
25
26 controller.add(3);
27 controller.add(4);
28 controller.close();
29 });
30
31 test("cancels the subscription to the broadcast stream when it's canceled",
32 () async {
33 var canceled = false;
34 var controller = new StreamController.broadcast(onCancel: () {
35 canceled = true;
36 });
37 var stream = controller.stream.transform(
38 const SingleSubscriptionTransformer());
39 await flushMicrotasks();
40 expect(canceled, isFalse);
41
42 var subscription = stream.listen(null);
43 await flushMicrotasks();
44 expect(canceled, isFalse);
45
46 subscription.cancel();
47 await flushMicrotasks();
48 expect(canceled, isTrue);
49 });
50 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698