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

Side by Side Diff: tests/language/async_star_cancels_after_await_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(period) async* {
12 var timer;
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++;
Lasse Reichstein Nielsen 2016/02/08 21:04:35 should there be a yield here?
floitsch 2016/02/09 16:56:34 No. I thought that async* functions can be cancele
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 new Timer(const Duration(milliseconds: 100), () async {
41 await subscription.cancel();
42 Expect.listEquals(["main", "listen", "cancel", "finally"], events);
43 asyncEnd();
44 });
45 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698