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

Unified Diff: tests/language/await_for_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_for_cancel_test.dart ('k') | tests/language/await_not_started_immediately_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/await_for_test.dart
diff --git a/tests/language/await_for_test.dart b/tests/language/await_for_test.dart
index 9d224645971a79530fcbeb97378b69b393ef8beb..8c6f18e94e548d25057acdfeaef70c9a56c0e247 100644
--- a/tests/language/await_for_test.dart
+++ b/tests/language/await_for_test.dart
@@ -38,7 +38,32 @@ consumeTwo() async {
await for (var x in makeMeAStream()) {
t2.record(x);
}
- t2.record("X");
+ t2.record("Y");
+}
+
+Trace t3 = new Trace();
+
+consumeNested() async {
+ await for (var x in makeMeAStream()) {
+ t3.record(x);
+ await for (var y in makeMeAStream()) {
+ t3.record(y);
+ }
+ t3.record("|");
+ }
+ t3.record("Z");
+}
+
+Trace t4 = new Trace();
+
+consumeSomeOfInfinite() async {
+ int i = 0;
+ await for (var x in infiniteStream()) {
+ i++;
+ if (i > 10) break;
+ t4.record(x);
+ }
+ t4.record("U");
}
main() {
@@ -47,18 +72,23 @@ main() {
var f2 = consumeTwo();
t2.record("T2:");
+
+ var f3 = consumeNested();
+ t3.record("T3:");
+
+ var f4 = consumeSomeOfInfinite();
+ t4.record("T4:");
asyncStart();
- Future.wait([f1, f2]).then((_) {
- print("Trace 1: $t1");
- print("Trace 2: $t2");
+ Future.wait([f1, f2, f3, f4]).then((_) {
Expect.equals("T1:12345X", t1.toString());
- Expect.equals("T2:12345X", t2.toString());
+ Expect.equals("T2:12345Y", t2.toString());
+ Expect.equals("T3:112345|212345|312345|412345|512345|Z", t3.toString());
+ Expect.equals("T4:12345678910U", t4.toString());
asyncEnd();
});
}
-
// Create a stream that produces numbers [1, 2, ... maxCount]
Stream timedCounter(int maxCount) {
StreamController controller;
@@ -93,3 +123,34 @@ Stream timedCounter(int maxCount) {
return controller.stream;
}
+
+// Create a stream that produces numbers [1, 2, ... ]
+Stream infiniteStream() {
+ 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: stopTimer);
+
+ return controller.stream;
+}
« no previous file with comments | « tests/language/await_for_cancel_test.dart ('k') | tests/language/await_not_started_immediately_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698