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

Side by Side Diff: tests/language/async_star_no_cancel_test.dart

Issue 1677063003: More tests for async* functions (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add another test. Created 4 years, 10 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
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 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart";
8
9 var events = [];
10
11 ticker() async* {
12 var sc;
13 var sentTickCount = 0;
14 sc = new StreamController(onListen: () {
15 events.add("listen");
16 }, onCancel: () {
17 events.add("cancel");
18 });
19
20 try {
21 var counter = 0;
22 await for (var tick in sc.stream) {
23 counter++;
Lasse Reichstein Nielsen 2016/02/08 21:04:35 Should there be a yield here? Otherwise you have
floitsch 2016/02/09 16:56:34 Yes. The tests now make sure that there is no canc
24 }
25 } finally {
26 events.add("finally");
27 }
28 }
29
30 void main() {
31 asyncStart();
32 events.add("main");
33 final subscription = ticker().listen((val) { });
34
35 bool cancelFinished = false;
36 // Cancel the subscription.
37 // The async* function is blocked on an `await` (the inner stream) and won't
38 // be able to complete.
39 Timer.run(() {
40 subscription.cancel().then((_) => cancelFinished = true);
41 });
42
43 new Timer(const Duration(milliseconds: 100), () {
44 Expect.isFalse(cancelFinished);
45 Expect.listEquals(["main", "listen"], events);
46 asyncEnd();
47 });
48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698