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

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

Issue 11740027: Rename unsubscribe to cancel. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Fix error message. Created 7 years, 11 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
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 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 const int KB = 1024; 10 const int KB = 1024;
11 const int MB = KB * KB; 11 const int MB = KB * KB;
12 const int GB = KB * KB * KB; 12 const int GB = KB * KB * KB;
13 13
14 class SlowConsumer extends StreamPipe { 14 class SlowConsumer extends StreamPipe {
15 var current = new Future.immediate(0); 15 var current = new Future.immediate(0);
16 final int bytesPerSecond; 16 final int bytesPerSecond;
17 17
18 SlowConsumer(int this.bytesPerSecond); 18 SlowConsumer(int this.bytesPerSecond);
19 19
20 Future bind(Stream stream) { 20 Future bind(Stream stream) {
21 Completer completer = new Completer(); 21 Completer completer = new Completer();
22 var subscription; 22 var subscription;
23 subscription = stream.subscribe( 23 subscription = stream.listen(
24 onData: (List<int> data) { 24 (List<int> data) {
25 current = current 25 current = current
26 .then((count) { 26 .then((count) {
27 // Simulated amount of time it takes to handle the data. 27 // Simulated amount of time it takes to handle the data.
28 int ms = data.length * 1000 ~/ bytesPerSecond; 28 int ms = data.length * 1000 ~/ bytesPerSecond;
29 subscription.pause(); 29 subscription.pause();
30 return new Future.delayed(ms, () { 30 return new Future.delayed(ms, () {
31 subscription.resume(); 31 subscription.resume();
32 // Make sure we use data here to keep tracking it. 32 // Make sure we use data here to keep tracking it.
33 return count + data.length; 33 return count + data.length;
34 }); 34 });
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // file). If the consumer doesn't pause the data-provider it will run out of 83 // file). If the consumer doesn't pause the data-provider it will run out of
84 // heap-space. 84 // heap-space.
85 85
86 new DataProvider(800 * MB, 100 * MB, 1 * MB) 86 new DataProvider(800 * MB, 100 * MB, 1 * MB)
87 .pipe(new SlowConsumer(200 * MB)) 87 .pipe(new SlowConsumer(200 * MB))
88 .then((count) { 88 .then((count) {
89 port.close(); 89 port.close();
90 Expect.equals(100 * MB, count); 90 Expect.equals(100 * MB, count);
91 }); 91 });
92 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698