| 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=32 | 5 // VMOptions=--old_gen_heap_size=32 |
| 6 | 6 |
| 7 library slow_consumer3_test; | 7 library slow_consumer3_test; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 subscription = stream.listen( | 28 subscription = stream.listen( |
| 29 (List<int> data) { | 29 (List<int> data) { |
| 30 receivedCount += data.length; | 30 receivedCount += data.length; |
| 31 usedBufferSize += data.length; | 31 usedBufferSize += data.length; |
| 32 bufferedData.add(data); | 32 bufferedData.add(data); |
| 33 int currentBufferedDataLength = bufferedData.length; | 33 int currentBufferedDataLength = bufferedData.length; |
| 34 if (usedBufferSize > bufferSize) { | 34 if (usedBufferSize > bufferSize) { |
| 35 subscription.pause(); | 35 subscription.pause(); |
| 36 usedBufferSize = 0; | 36 usedBufferSize = 0; |
| 37 int ms = data.length * 1000 ~/ bytesPerSecond; | 37 int ms = data.length * 1000 ~/ bytesPerSecond; |
| 38 new Timer(ms, (_) { | 38 Duration duration = new Duration(milliseconds: ms); |
| 39 new Timer(duration, () { |
| 39 for (int i = 0; i < currentBufferedDataLength; i++) { | 40 for (int i = 0; i < currentBufferedDataLength; i++) { |
| 40 bufferedData[i] = null; | 41 bufferedData[i] = null; |
| 41 } | 42 } |
| 42 subscription.resume(); | 43 subscription.resume(); |
| 43 }); | 44 }); |
| 44 } | 45 } |
| 45 }, | 46 }, |
| 46 onDone: () { result.complete(receivedCount); }); | 47 onDone: () { result.complete(receivedCount); }); |
| 47 return result.future; | 48 return result.future; |
| 48 } | 49 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 71 // file). If the consumer doesn't pause the data-provider it will run out of | 72 // file). If the consumer doesn't pause the data-provider it will run out of |
| 72 // heap-space. | 73 // heap-space. |
| 73 | 74 |
| 74 dataGenerator(100 * MB, 512 * KB) | 75 dataGenerator(100 * MB, 512 * KB) |
| 75 .pipe(new SlowConsumer(200 * MB, 3 * MB)) | 76 .pipe(new SlowConsumer(200 * MB, 3 * MB)) |
| 76 .then((count) { | 77 .then((count) { |
| 77 port.close(); | 78 port.close(); |
| 78 Expect.equals(100 * MB, count); | 79 Expect.equals(100 * MB, count); |
| 79 }); | 80 }); |
| 80 } | 81 } |
| OLD | NEW |