| OLD | NEW |
| 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 /** | 5 /** |
| 6 * Generic utility functions. Stuff that should possibly be in core. | 6 * Generic utility functions. Stuff that should possibly be in core. |
| 7 */ | 7 */ |
| 8 library utils; | 8 library utils; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 future.then((_) => fn()); | 48 future.then((_) => fn()); |
| 49 future.handleException((_) { | 49 future.handleException((_) { |
| 50 fn(); | 50 fn(); |
| 51 return false; | 51 return false; |
| 52 }); | 52 }); |
| 53 } | 53 } |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * Flattens nested lists into a single list containing only non-list elements. | 56 * Flattens nested lists into a single list containing only non-list elements. |
| 57 */ | 57 */ |
| 58 List flatten(List nested) { | 58 List flatten(Iterable nested) { |
| 59 var result = []; | 59 var result = []; |
| 60 helper(list) { | 60 helper(list) { |
| 61 for (var element in list) { | 61 for (var element in list) { |
| 62 if (element is List) { | 62 if (element is List) { |
| 63 helper(element); | 63 helper(element); |
| 64 } else { | 64 } else { |
| 65 result.add(element); | 65 result.add(element); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 } | 68 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes).digest()); | 124 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes).digest()); |
| 125 | 125 |
| 126 /** | 126 /** |
| 127 * Returns a [Future] that completes in [milliSeconds]. | 127 * Returns a [Future] that completes in [milliSeconds]. |
| 128 */ | 128 */ |
| 129 Future sleep(int milliSeconds) { | 129 Future sleep(int milliSeconds) { |
| 130 var completer = new Completer(); | 130 var completer = new Completer(); |
| 131 new Timer(milliSeconds, completer.complete); | 131 new Timer(milliSeconds, completer.complete); |
| 132 return completer.future; | 132 return completer.future; |
| 133 } | 133 } |
| OLD | NEW |