Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Unified Diff: utils/pub/utils.dart

Issue 11299028: Move CurlClient to Pub so that it can access resources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review change Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/io.dart ('k') | utils/tests/pub/curl_client_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/utils.dart
diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart
index 21275f8b51bf084b8a42fd7429c1b9067e6180dd..40978856147a4cff7296af28aeca2a7435fdb1c4 100644
--- a/utils/pub/utils.dart
+++ b/utils/pub/utils.dart
@@ -129,3 +129,24 @@ Future sleep(int milliSeconds) {
new Timer(milliSeconds, completer.complete);
return completer.future;
}
+
+/// Configures [future] so that its result (success or exception) is passed on
+/// to [completer].
+void chainToCompleter(Future future, Completer completer) {
+ future.handleException((e) {
+ completer.completeException(e);
+ return true;
+ });
+ future.then(completer.complete);
+}
+
+/// Like [String.split], but only splits on the first occurrence of the pattern.
+/// This will always return an array of two elements or fewer.
+List<String> split1(String toSplit, String pattern) {
+ if (toSplit.isEmpty) return <String>[];
+
+ var index = toSplit.indexOf(pattern);
+ if (index == -1) return [toSplit];
+ return [toSplit.substring(0, index),
+ toSplit.substring(index + pattern.length)];
+}
« no previous file with comments | « utils/pub/io.dart ('k') | utils/tests/pub/curl_client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698