| OLD | NEW |
| 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 |
| 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 |
| 22 /// any code to run, as long as it's not waiting on some external event. |
| 23 Future pumpEventQueue([int times=200]) { |
| 24 if (times == 0) return new Future.immediate(null); |
| 25 return new Future.immediate(null).then((_) => pumpEventQueue(times - 1)); |
| 26 } |
| OLD | NEW |