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

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

Issue 1259793005: Add docs for new util methods. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 4 months 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
« no previous file with comments | « no previous file | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 test.utils; 5 library test.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:math' as math; 9 import 'dart:math' as math;
10 10
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 }, onError: (error, stackTrace) { 316 }, onError: (error, stackTrace) {
317 completer.completeError(error, stackTrace); 317 completer.completeError(error, stackTrace);
318 subscription.cancel(); 318 subscription.cancel();
319 }, onDone: () { 319 }, onDone: () {
320 completer.complete(); 320 completer.complete();
321 }); 321 });
322 322
323 return completer.future; 323 return completer.future;
324 } 324 }
325 325
326 /// Returns a [CancelableFuture] that returns the next value of [queue] unless
327 /// it's canceled.
328 ///
329 /// If the future is canceled, [queue] is not moved forward at all. Note that
330 /// it's not safe to call further methods on [queue] until this future has
331 /// either completed or been canceled.
326 CancelableFuture cancelableNext(StreamQueue queue) { 332 CancelableFuture cancelableNext(StreamQueue queue) {
327 var fork = queue.fork(); 333 var fork = queue.fork();
328 var completer = new CancelableCompleter(() => fork.cancel(immediate: true)); 334 var completer = new CancelableCompleter(() => fork.cancel(immediate: true));
329 completer.complete(fork.next.then((_) { 335 completer.complete(fork.next.then((_) {
330 fork.cancel(); 336 fork.cancel();
331 return queue.next; 337 return queue.next;
332 })); 338 }));
333 return completer.future; 339 return completer.future;
334 } 340 }
335 341
342 /// Returns the result of whichever of [futures] completes first, and cancels
343 /// the others.
336 Future race(Iterable<CancelableFuture> futures) { 344 Future race(Iterable<CancelableFuture> futures) {
337 var completer = new Completer.sync(); 345 var completer = new Completer.sync();
338 for (var future in futures) { 346 for (var future in futures) {
339 future.then((value) { 347 future.then((value) {
340 if (!completer.isCompleted) completer.complete(value); 348 if (!completer.isCompleted) completer.complete(value);
341 }).catchError((error, stackTrace) { 349 }).catchError((error, stackTrace) {
342 if (!completer.isCompleted) completer.completeError(error, stackTrace); 350 if (!completer.isCompleted) completer.completeError(error, stackTrace);
343 }); 351 });
344 } 352 }
345 353
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 427 }
420 } 428 }
421 429
422 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. 430 /// Returns middleware that nests all requests beneath the URL prefix [beneath].
423 shelf.Middleware nestingMiddleware(String beneath) { 431 shelf.Middleware nestingMiddleware(String beneath) {
424 return (handler) { 432 return (handler) {
425 var pathHandler = new PathHandler()..add(beneath, handler); 433 var pathHandler = new PathHandler()..add(beneath, handler);
426 return pathHandler.handler; 434 return pathHandler.handler;
427 }; 435 };
428 } 436 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698