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

Unified Diff: tests/lib/async/slow_consumer_test.dart

Issue 12033019: Make StreamController take on{Pause,Subscription]StateChange as arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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/lib/async/slow_consumer2_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/slow_consumer_test.dart
diff --git a/tests/lib/async/slow_consumer_test.dart b/tests/lib/async/slow_consumer_test.dart
index 11c087d3dcb6c4d9d74992969fcf6ff6e91bedcb..027924eb393c0212dbd780bc2387049c82e3c646 100644
--- a/tests/lib/async/slow_consumer_test.dart
+++ b/tests/lib/async/slow_consumer_test.dart
@@ -41,20 +41,24 @@ class SlowConsumer extends StreamConsumer {
}
}
-class DataProvider extends StreamController {
+class DataProvider {
final int chunkSize;
final int bytesPerSecond;
int sentCount = 0;
int targetCount;
+ StreamController controller;
DataProvider(int this.bytesPerSecond, int this.targetCount, this.chunkSize) {
+ controller = new StreamController(onPauseStateChange: onPauseStateChange);
new Timer(0, (_) => send());
}
+ Stream get stream => controller.stream;
+
send() {
- if (isPaused) return;
+ if (controller.isPaused) return;
if (sentCount == targetCount) {
- close();
+ controller.close();
return;
}
int listSize = chunkSize;
@@ -63,9 +67,9 @@ class DataProvider extends StreamController {
listSize -= sentCount - targetCount;
sentCount = targetCount;
}
- add(new List.fixedLength(listSize));
+ controller.add(new List.fixedLength(listSize));
int ms = listSize * 1000 ~/ bytesPerSecond;
- if (!isPaused) new Timer(ms, (_) => send());
+ if (!controller.isPaused) new Timer(ms, (_) => send());
}
onPauseStateChange() {
@@ -85,7 +89,7 @@ main() {
// file). If the consumer doesn't pause the data-provider it will run out of
// heap-space.
- new DataProvider(800 * MB, 100 * MB, 1 * MB)
+ new DataProvider(800 * MB, 100 * MB, 1 * MB).stream
.pipe(new SlowConsumer(200 * MB))
.then((count) {
port.close();
« no previous file with comments | « tests/lib/async/slow_consumer2_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698