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

Unified Diff: tests/language/await_for_cancel_test.dart

Issue 839323003: Implementation of async-await transformation on js ast. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/language/await_exceptions_test.dart ('k') | tests/language/await_for_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/await_for_cancel_test.dart
diff --git a/tests/language/await_for_cancel_test.dart b/tests/language/await_for_cancel_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6e3883d3cda336bdb6a50995c1f0a3a0f9ec9964
--- /dev/null
+++ b/tests/language/await_for_cancel_test.dart
@@ -0,0 +1,88 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+bool cancelled;
+
+test1() async {
+ cancelled = false;
+ try {
+ StreamController controller = infiniteStreamController();
+ outer: while(true) {
+ await for (var x in controller.stream) {
+ for (int j = 0; j < 10; j++) {
+ if (j == 5) break outer;
+ }
+ }
+ }
+ } finally {
+ Expect.isTrue(cancelled);
+ }
+}
+
+test2() async {
+ cancelled = false;
+ try {
+ StreamController controller = infiniteStreamController();
+ bool first = true;
+ outer: while(true) {
+ if (first) {
+ first = false;
+ } else {
+ break;
+ }
+ await for (var x in controller.stream) {
+ for (int j = 0; j < 10; j++) {
+ if (j == 5) continue outer;
+ }
+ }
+ }
+ } finally {
+ Expect.isTrue(cancelled);
+ }
+}
+
+main() async {
+ await test1();
+ await test2();
+
+}
+
+
+// Create a stream that produces numbers [1, 2, ... ]
+StreamController infiniteStreamController() {
+ StreamController controller;
+ Timer timer;
+ int counter = 0;
+
+ void tick(_) {
+ counter++;
+ controller.add(counter); // Ask stream to send counter values as event.
+ }
+
+ void startTimer() {
+ timer = new Timer.periodic(const Duration(milliseconds: 10), tick);
+ }
+
+ void stopTimer() {
+ if (timer != null) {
+ timer.cancel();
+ timer = null;
+ }
+ }
+
+ controller = new StreamController(
+ onListen: startTimer,
+ onPause: stopTimer,
+ onResume: startTimer,
+ onCancel: () {
+ cancelled = true;
+ stopTimer();
+ });
+
+ return controller;
+}
« no previous file with comments | « tests/language/await_exceptions_test.dart ('k') | tests/language/await_for_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698