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

Side by Side Diff: pkg/http/lib/src/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 | « pkg/http/lib/src/curl_client.dart ('k') | pkg/http/test/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 library utils; 5 library utils;
6 6
7 import 'dart:crypto'; 7 import 'dart:crypto';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'dart:scalarlist'; 10 import 'dart:scalarlist';
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 /// The return values of all [Future]s are discarded. Any errors will cause the 178 /// The return values of all [Future]s are discarded. Any errors will cause the
179 /// iteration to stop and will be piped through the return value. 179 /// iteration to stop and will be piped through the return value.
180 Future forEachFuture(Iterable input, Future fn(element)) { 180 Future forEachFuture(Iterable input, Future fn(element)) {
181 var iterator = input.iterator(); 181 var iterator = input.iterator();
182 Future nextElement(_) { 182 Future nextElement(_) {
183 if (!iterator.hasNext) return new Future.immediate(null); 183 if (!iterator.hasNext) return new Future.immediate(null);
184 return fn(iterator.next()).chain(nextElement); 184 return fn(iterator.next()).chain(nextElement);
185 } 185 }
186 return nextElement(null); 186 return nextElement(null);
187 } 187 }
188
189 /// Creates a temporary directory and passes its path to [fn]. Once the [Future]
190 /// returned by [fn] completes, the temporary directory and all its contents
191 /// will be deleted.
192 Future withTempDir(Future fn(String path)) {
193 var tempDir;
194 var future = new Directory('').createTemp().chain((dir) {
195 tempDir = dir;
196 return fn(tempDir.path);
197 });
198 future.onComplete((_) => tempDir.delete(recursive: true));
199 return future;
200 }
201
202 /// Configures [future] so that its result (success or exception) is passed on
203 /// to [completer].
204 void chainToCompleter(Future future, Completer completer) {
205 future.handleException((e) {
206 completer.completeException(e);
207 return true;
208 });
209 future.then(completer.complete);
210 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/curl_client.dart ('k') | pkg/http/test/curl_client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698