Chromium Code Reviews| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 return false; | 97 return false; |
| 98 } | 98 } |
| 99 | 99 |
| 100 /// Returns the hex-encoded sha1 hash of [source]. | 100 /// Returns the hex-encoded sha1 hash of [source]. |
| 101 String sha1(String source) { | 101 String sha1(String source) { |
| 102 var sha = new SHA1(); | 102 var sha = new SHA1(); |
| 103 sha.add(source.charCodes); | 103 sha.add(source.charCodes); |
| 104 return CryptoUtils.bytesToHex(sha.close()); | 104 return CryptoUtils.bytesToHex(sha.close()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /// Invokes the given callback asynchronously. Returns a [Future] that completes | |
| 108 /// to the result of [callback]. | |
|
nweiz
2013/02/01 02:05:55
Move all those comments about error-capturing in h
Bob Nystrom
2013/02/01 23:17:21
Done.
| |
| 109 Future defer(callback()) { | |
| 110 return new Future.immediate(null).then((_) => callback()); | |
| 111 } | |
| 112 | |
| 107 /// Returns a [Future] that completes in [milliseconds]. | 113 /// Returns a [Future] that completes in [milliseconds]. |
| 108 Future sleep(int milliseconds) { | 114 Future sleep(int milliseconds) { |
| 109 var completer = new Completer(); | 115 var completer = new Completer(); |
| 110 new Timer(milliseconds, (_) => completer.complete()); | 116 new Timer(milliseconds, (_) => completer.complete()); |
| 111 return completer.future; | 117 return completer.future; |
| 112 } | 118 } |
| 113 | 119 |
| 114 /// Configures [future] so that its result (success or exception) is passed on | 120 /// Configures [future] so that its result (success or exception) is passed on |
| 115 /// to [completer]. | 121 /// to [completer]. |
| 116 void chainToCompleter(Future future, Completer completer) { | 122 void chainToCompleter(Future future, Completer completer) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 176 |
| 171 /// Add all key/value pairs from [source] to [destination], overwriting any | 177 /// Add all key/value pairs from [source] to [destination], overwriting any |
| 172 /// pre-existing values. | 178 /// pre-existing values. |
| 173 void mapAddAll(Map destination, Map source) => | 179 void mapAddAll(Map destination, Map source) => |
| 174 source.forEach((key, value) => destination[key] = value); | 180 source.forEach((key, value) => destination[key] = value); |
| 175 | 181 |
| 176 /// Decodes a URL-encoded string. Unlike [decodeUriComponent], this includes | 182 /// Decodes a URL-encoded string. Unlike [decodeUriComponent], this includes |
| 177 /// replacing `+` with ` `. | 183 /// replacing `+` with ` `. |
| 178 String urlDecode(String encoded) => | 184 String urlDecode(String encoded) => |
| 179 decodeUriComponent(encoded.replaceAll("+", " ")); | 185 decodeUriComponent(encoded.replaceAll("+", " ")); |
| OLD | NEW |