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 barback.utils; | 5 library barback.utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 /// Converts a number in the range [0-255] to a two digit hex string. | 9 /// Converts a number in the range [0-255] to a two digit hex string. |
10 /// | 10 /// |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 /// any code to run, as long as it's not waiting on some external event. | 94 /// any code to run, as long as it's not waiting on some external event. |
95 Future pumpEventQueue([int times=20]) { | 95 Future pumpEventQueue([int times=20]) { |
96 if (times == 0) return new Future.value(); | 96 if (times == 0) return new Future.value(); |
97 // We use a delayed future to allow runAsync events to finish. The | 97 // We use a delayed future to allow runAsync events to finish. The |
98 // Future.value or Future() constructors use runAsync themselves and would | 98 // Future.value or Future() constructors use runAsync themselves and would |
99 // therefore not wait for runAsync callbacks that are scheduled after invoking | 99 // therefore not wait for runAsync callbacks that are scheduled after invoking |
100 // this method. | 100 // this method. |
101 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); | 101 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
102 } | 102 } |
103 | 103 |
| 104 /// Like [new Future], but avoids issue 11911 by using [new Future.value] under |
| 105 /// the covers. |
| 106 Future newFuture(callback()) => new Future.value().then((_) => callback()); |
OLD | NEW |