| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 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(onPauseStateChange: onPauseStateChange); | 71 controller = new StreamController( |
| 72 onPause: onPauseStateChange, |
| 73 onResume: onPauseStateChange); |
| 72 Timer.run(send); | 74 Timer.run(send); |
| 73 } | 75 } |
| 74 | 76 |
| 75 Stream get stream => controller.stream; | 77 Stream get stream => controller.stream; |
| 76 | 78 |
| 77 send() { | 79 send() { |
| 78 if (pendingSend != null) { | 80 if (pendingSend != null) { |
| 79 pendingSend.cancel(); | 81 pendingSend.cancel(); |
| 80 pendingSend = null; | 82 pendingSend = null; |
| 81 } | 83 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // file). If the consumer doesn't pause the data-provider it will run out of | 117 // file). If the consumer doesn't pause the data-provider it will run out of |
| 116 // heap-space. | 118 // heap-space. |
| 117 | 119 |
| 118 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream | 120 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream |
| 119 .pipe(new SlowConsumer(200 * MB)) | 121 .pipe(new SlowConsumer(200 * MB)) |
| 120 .then((count) { | 122 .then((count) { |
| 121 port.close(); | 123 port.close(); |
| 122 Expect.equals(100 * MB, count); | 124 Expect.equals(100 * MB, count); |
| 123 }); | 125 }); |
| 124 } | 126 } |
| OLD | NEW |