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_consumer_test; | 7 library slow_consumer_test; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 Future consume(Stream stream) { | 22 Future consume(Stream stream) { |
23 Completer completer = new Completer(); | 23 Completer completer = new Completer(); |
24 var subscription; | 24 var subscription; |
25 subscription = stream.listen( | 25 subscription = stream.listen( |
26 (List<int> data) { | 26 (List<int> data) { |
27 current = current | 27 current = current |
28 .then((count) { | 28 .then((count) { |
29 // Simulated amount of time it takes to handle the data. | 29 // Simulated amount of time it takes to handle the data. |
30 int ms = data.length * 1000 ~/ bytesPerSecond; | 30 int ms = data.length * 1000 ~/ bytesPerSecond; |
| 31 Duration duration = new Duration(milliseconds: ms); |
31 subscription.pause(); | 32 subscription.pause(); |
32 return new Future.delayed(ms, () { | 33 return new Future.delayed(duration, () { |
33 subscription.resume(); | 34 subscription.resume(); |
34 // Make sure we use data here to keep tracking it. | 35 // Make sure we use data here to keep tracking it. |
35 return count + data.length; | 36 return count + data.length; |
36 }); | 37 }); |
37 }); | 38 }); |
38 }, | 39 }, |
39 onDone: () { current.then((count) { completer.complete(count); }); }); | 40 onDone: () { current.then((count) { completer.complete(count); }); }); |
40 return completer.future; | 41 return completer.future; |
41 } | 42 } |
42 } | 43 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // file). If the consumer doesn't pause the data-provider it will run out of | 91 // file). If the consumer doesn't pause the data-provider it will run out of |
91 // heap-space. | 92 // heap-space. |
92 | 93 |
93 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream | 94 new DataProvider(800 * MB, 100 * MB, 1 * MB).stream |
94 .pipe(new SlowConsumer(200 * MB)) | 95 .pipe(new SlowConsumer(200 * MB)) |
95 .then((count) { | 96 .then((count) { |
96 port.close(); | 97 port.close(); |
97 Expect.equals(100 * MB, count); | 98 Expect.equals(100 * MB, count); |
98 }); | 99 }); |
99 } | 100 } |
OLD | NEW |