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

Side by Side Diff: pkg/scheduled_test/lib/src/utils.dart

Issue 12391003: Reduce the number of times pumpEventQueue pumps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « no previous file | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library utils; 5 library utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 /// Configures [future] so that its result (success or exception) is passed on 9 /// Configures [future] so that its result (success or exception) is passed on
10 /// to [completer]. 10 /// to [completer].
11 void chainToCompleter(Future future, Completer completer) { 11 void chainToCompleter(Future future, Completer completer) {
12 future.then((value) => completer.complete(value), 12 future.then((value) => completer.complete(value),
13 onError: (e) => completer.completeError(e.error, e.stackTrace)); 13 onError: (e) => completer.completeError(e.error, e.stackTrace));
14 } 14 }
15 15
16 /// Prepends each line in [text] with [prefix]. 16 /// Prepends each line in [text] with [prefix].
17 String prefixLines(String text, {String prefix: '| '}) => 17 String prefixLines(String text, {String prefix: '| '}) =>
18 text.split('\n').map((line) => '$prefix$line').join('\n'); 18 text.split('\n').map((line) => '$prefix$line').join('\n');
19 19
20 /// Returns a [Future] that completes after pumping the event queue [times] 20 /// Returns a [Future] that completes after pumping the event queue [times]
21 /// times. By default, this should pump the event queue enough times to allow 21 /// times. By default, this should pump the event queue enough times to allow
22 /// any code to run, as long as it's not waiting on some external event. 22 /// any code to run, as long as it's not waiting on some external event.
23 Future pumpEventQueue([int times=200]) { 23 Future pumpEventQueue([int times=20]) {
24 if (times == 0) return new Future.immediate(null); 24 if (times == 0) return new Future.immediate(null);
25 return new Future.immediate(null).then((_) => pumpEventQueue(times - 1)); 25 return new Future.immediate(null).then((_) => pumpEventQueue(times - 1));
26 } 26 }
27 27
28 /// Returns whether [iterable1] has the same elements in the same order as 28 /// Returns whether [iterable1] has the same elements in the same order as
29 /// [iterable2]. The elements are compared using `==`. 29 /// [iterable2]. The elements are compared using `==`.
30 bool orderedIterableEquals(Iterable iterable1, Iterable iterable2) { 30 bool orderedIterableEquals(Iterable iterable1, Iterable iterable2) {
31 var iter1 = iterable1.iterator; 31 var iter1 = iterable1.iterator;
32 var iter2 = iterable2.iterator; 32 var iter2 = iterable2.iterator;
33 33
(...skipping 19 matching lines...) Expand all
53 stream.listen( 53 stream.listen(
54 controller.add, 54 controller.add,
55 onError: (error) => controller.signalError(error), 55 onError: (error) => controller.signalError(error),
56 onDone: controller.close); 56 onDone: controller.close);
57 }).catchError((e) { 57 }).catchError((e) {
58 controller.signalError(e); 58 controller.signalError(e);
59 controller.close(); 59 controller.close();
60 }); 60 });
61 return controller.stream; 61 return controller.stream;
62 } 62 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698