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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/io.dart ('k') | utils/tests/pub/curl_client_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:crypto'; 10 import 'dart:crypto';
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes).digest()); 122 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes).digest());
123 123
124 /** 124 /**
125 * Returns a [Future] that completes in [milliSeconds]. 125 * Returns a [Future] that completes in [milliSeconds].
126 */ 126 */
127 Future sleep(int milliSeconds) { 127 Future sleep(int milliSeconds) {
128 var completer = new Completer(); 128 var completer = new Completer();
129 new Timer(milliSeconds, completer.complete); 129 new Timer(milliSeconds, completer.complete);
130 return completer.future; 130 return completer.future;
131 } 131 }
132
133 /// Configures [future] so that its result (success or exception) is passed on
134 /// to [completer].
135 void chainToCompleter(Future future, Completer completer) {
136 future.handleException((e) {
137 completer.completeException(e);
138 return true;
139 });
140 future.then(completer.complete);
141 }
142
143 /// Like [String.split], but only splits on the first occurrence of the pattern.
144 /// This will always return an array of two elements or fewer.
145 List<String> split1(String toSplit, String pattern) {
146 if (toSplit.isEmpty) return <String>[];
147
148 var index = toSplit.indexOf(pattern);
149 if (index == -1) return [toSplit];
150 return [toSplit.substring(0, index),
151 toSplit.substring(index + pattern.length)];
152 }
OLDNEW
« 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