OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // VMOptions=--old_gen_heap_size=64 | 5 // VMOptions=--old_gen_heap_size=64 |
6 | 6 |
7 library slow_consumer_test; | 7 library slow_consumer_test; |
8 | 8 |
9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
10 import 'dart:async'; | 10 import 'dart:async'; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 class DataProvider { | 62 class DataProvider { |
63 final int chunkSize; | 63 final int chunkSize; |
64 final int bytesPerSecond; | 64 final int bytesPerSecond; |
65 int sentCount = 0; | 65 int sentCount = 0; |
66 int targetCount; | 66 int targetCount; |
67 StreamController controller; | 67 StreamController controller; |
68 Timer pendingSend; | 68 Timer pendingSend; |
69 | 69 |
70 DataProvider(int this.bytesPerSecond, int this.targetCount, this.chunkSize) { | 70 DataProvider(int this.bytesPerSecond, int this.targetCount, this.chunkSize) { |
71 controller = new StreamController( | 71 controller = new StreamController( |
| 72 sync: true, |
72 onPause: onPauseStateChange, | 73 onPause: onPauseStateChange, |
73 onResume: onPauseStateChange); | 74 onResume: onPauseStateChange); |
74 Timer.run(send); | 75 Timer.run(send); |
75 } | 76 } |
76 | 77 |
77 Stream get stream => controller.stream; | 78 Stream get stream => controller.stream; |
78 | 79 |
79 send() { | 80 send() { |
80 if (pendingSend != null) { | 81 if (pendingSend != null) { |
81 pendingSend.cancel(); | 82 pendingSend.cancel(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // file). If the consumer doesn't pause the data-provider it will run out of | 118 // file). If the consumer doesn't pause the data-provider it will run out of |
118 // heap-space. | 119 // heap-space. |
119 | 120 |
120 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream | 121 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream |
121 .pipe(new SlowConsumer(200 * MB)) | 122 .pipe(new SlowConsumer(200 * MB)) |
122 .then((count) { | 123 .then((count) { |
123 port.close(); | 124 port.close(); |
124 Expect.equals(100 * MB, count); | 125 Expect.equals(100 * MB, count); |
125 }); | 126 }); |
126 } | 127 } |
OLD | NEW |