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

Side by Side Diff: pkg/http/lib/src/utils.dart

Issue 11394003: Add an HTTP client based on Curl. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 /// The return values of all [Future]s are discarded. Any errors will cause the 176 /// The return values of all [Future]s are discarded. Any errors will cause the
177 /// iteration to stop and will be piped through the return value. 177 /// iteration to stop and will be piped through the return value.
178 Future forEachFuture(Iterable input, Future fn(element)) { 178 Future forEachFuture(Iterable input, Future fn(element)) {
179 var iterator = input.iterator(); 179 var iterator = input.iterator();
180 Future nextElement(_) { 180 Future nextElement(_) {
181 if (!iterator.hasNext) return new Future.immediate(null); 181 if (!iterator.hasNext) return new Future.immediate(null);
182 return fn(iterator.next()).chain(nextElement); 182 return fn(iterator.next()).chain(nextElement);
183 } 183 }
184 return nextElement(null); 184 return nextElement(null);
185 } 185 }
186
187 /// Creates a temporary directory and passes its path to [fn]. Once the [Future]
188 /// returned by [fn] completes, the temporary directory and all its contents
189 /// will be deleted.
Bob Nystrom 2012/11/07 23:15:15 Very nice.
190 Future withTempDir(Future fn(String path)) {
191 var tempDir;
192 var future = new Directory('').createTemp().chain((dir) {
193 tempDir = dir;
194 return fn(tempDir.path);
195 });
196 future.onComplete((_) => tempDir.delete(recursive: true));
197 return future;
198 }
199
200 /// Configures [future] so that its result (success or exception) is passed on
201 /// to [completer].
202 void chainToCompleter(Future future, Completer completer) {
203 future.handleException((e) {
204 completer.completeException(e);
205 return true;
206 });
207 future.then(completer.complete);
208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698