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

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

Issue 1677063003: More tests for async* functions (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update status file. 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 var timer;
12 ticker(period) async* {
13 var sc;
14 sc = new StreamController(onListen: () {
15 events.add("listen");
16 timer = new Timer.periodic(period, (_) {
17 sc.add(null);
18 });
19 }, onCancel: () {
20 events.add("cancel");
21 timer.cancel();
22 });
23
24 try {
25 var counter = 0;
26 await for (var tick in sc.stream) {
27 counter++;
28 }
29 } finally {
30 events.add("finally");
31 }
32 }
33
34 void main() {
35 asyncStart();
36 events.add("main");
37 final subscription =
38 ticker(const Duration(milliseconds: 20)).listen((val) { });
39
40 bool cancelFinished = false;
41 new Timer(const Duration(milliseconds: 100), () async {
42 // Despite the cancel call below, the stream doesn't stop, since there
43 // is no yield-point where it can cancel.
44 new Timer(const Duration(milliseconds: 30), () {
45 Expect.isFalse(cancelFinished);
46 Expect.listEquals(["main", "listen"], events);
47 timer.cancel();
48 asyncEnd();
49 });
50
51 await subscription.cancel();
52 // This line should never be reached, since the cancel-future doesn't
53 // complete.
54 cancelFinished = true;
55 });
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698