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 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
6 library utils; | 6 library utils; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:crypto'; | 9 import 'dart:crypto'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return false; | 138 return false; |
139 } | 139 } |
140 | 140 |
141 /// Returns the hex-encoded sha1 hash of [source]. | 141 /// Returns the hex-encoded sha1 hash of [source]. |
142 String sha1(String source) { | 142 String sha1(String source) { |
143 var sha = new SHA1(); | 143 var sha = new SHA1(); |
144 sha.add(source.codeUnits); | 144 sha.add(source.codeUnits); |
145 return CryptoUtils.bytesToHex(sha.close()); | 145 return CryptoUtils.bytesToHex(sha.close()); |
146 } | 146 } |
147 | 147 |
| 148 // TODO(nweiz): Use Future.of instead of this wherever we don't actually need |
| 149 // asynchrony. |
148 /// Invokes the given callback asynchronously. Returns a [Future] that completes | 150 /// Invokes the given callback asynchronously. Returns a [Future] that completes |
149 /// to the result of [callback]. | 151 /// to the result of [callback]. |
150 /// | 152 /// |
151 /// This is also used to wrap synchronous code that may thrown an exception to | 153 /// This is also used to wrap synchronous code that may thrown an exception to |
152 /// ensure that methods that have both sync and async code only report errors | 154 /// ensure that methods that have both sync and async code only report errors |
153 /// asynchronously. | 155 /// asynchronously. |
154 Future defer(callback()) { | 156 Future defer(callback()) { |
155 return new Future.immediate(null).then((_) => callback()); | 157 return new Future.immediate(null).then((_) => callback()); |
156 } | 158 } |
157 | 159 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 .then((resolved) => new Pair(key, resolved))); | 362 .then((resolved) => new Pair(key, resolved))); |
361 }); | 363 }); |
362 return Future.wait(pairs).then((resolvedPairs) { | 364 return Future.wait(pairs).then((resolvedPairs) { |
363 var map = {}; | 365 var map = {}; |
364 for (var pair in resolvedPairs) { | 366 for (var pair in resolvedPairs) { |
365 map[pair.first] = pair.last; | 367 map[pair.first] = pair.last; |
366 } | 368 } |
367 return map; | 369 return map; |
368 }); | 370 }); |
369 } | 371 } |
OLD | NEW |