Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(855)

Side by Side Diff: tests/lib/async/slow_consumer_test.dart

Issue 12224081: Change Future.delayed to take a Duration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments and made argument optional. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/async/future_test.dart ('k') | tests/lib/async/stream_from_iterable_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « tests/lib/async/future_test.dart ('k') | tests/lib/async/stream_from_iterable_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698