| 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 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 const int KB = 1024; | 9 const int KB = 1024; |
| 10 const int MB = KB * KB; | 10 const int MB = KB * KB; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 var current = new Future.immediate(0); | 35 var current = new Future.immediate(0); |
| 36 final int bytesPerSecond; | 36 final int bytesPerSecond; |
| 37 } | 37 } |
| 38 | 38 |
| 39 class DataProvider extends StreamController { | 39 class DataProvider extends StreamController { |
| 40 DataProvider(int bytesPerSecond, int runtime) { | 40 DataProvider(int bytesPerSecond, int runtime) { |
| 41 const int ms = 5; | 41 const int ms = 5; |
| 42 bool run = true; | 42 bool run = true; |
| 43 send() { | 43 send() { |
| 44 if (!run) return; | 44 if (!run) return; |
| 45 var wait = add(new List(bytesPerSecond * ms ~/ 1000)); | 45 var wait = add(new List.fixedLength(bytesPerSecond * ms ~/ 1000)); |
| 46 if (wait != null) { | 46 if (wait != null) { |
| 47 wait.then(() { | 47 wait.then(() { |
| 48 new Timer(ms, (_) => send()); | 48 new Timer(ms, (_) => send()); |
| 49 }); | 49 }); |
| 50 } else { | 50 } else { |
| 51 new Timer(ms, (_) => send()); | 51 new Timer(ms, (_) => send()); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 new Timer(ms, (_) => send()); | 54 new Timer(ms, (_) => send()); |
| 55 new Timer(runtime, (_) { | 55 new Timer(runtime, (_) { |
| 56 run = false; | 56 run = false; |
| 57 }); | 57 }); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 main() { | 61 main() { |
| 62 // 0.5 s * 200 MB/s = 100 MB. | 62 // 0.5 s * 200 MB/s = 100 MB. |
| 63 new DataProvider(400 * MB, 200).pipe(new SlowSink(100 * MB)); | 63 new DataProvider(400 * MB, 200).pipe(new SlowSink(100 * MB)); |
| 64 } | 64 } |
| OLD | NEW |