OLD | NEW |
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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 345 } |
346 | 346 |
347 /// Returns a [CancelableOperation] that returns the next value of [queue] | 347 /// Returns a [CancelableOperation] that returns the next value of [queue] |
348 /// unless it's canceled. | 348 /// unless it's canceled. |
349 /// | 349 /// |
350 /// If the operation is canceled, [queue] is not moved forward at all. Note that | 350 /// If the operation is canceled, [queue] is not moved forward at all. Note that |
351 /// it's not safe to call further methods on [queue] until this operation has | 351 /// it's not safe to call further methods on [queue] until this operation has |
352 /// either completed or been canceled. | 352 /// either completed or been canceled. |
353 CancelableOperation cancelableNext(StreamQueue queue) { | 353 CancelableOperation cancelableNext(StreamQueue queue) { |
354 var fork = queue.fork(); | 354 var fork = queue.fork(); |
355 var completer = new CancelableCompleter( | 355 var canceled = false; |
356 onCancel: () => fork.cancel(immediate: true)); | 356 var completer = new CancelableCompleter(onCancel: () { |
| 357 canceled = true; |
| 358 return fork.cancel(immediate: true); |
| 359 }); |
| 360 |
357 completer.complete(fork.next.then((_) { | 361 completer.complete(fork.next.then((_) { |
358 fork.cancel(); | 362 fork.cancel(); |
359 return queue.next; | 363 return canceled ? null : queue.next; |
360 })); | 364 })); |
| 365 |
361 return completer.operation; | 366 return completer.operation; |
362 } | 367 } |
363 | 368 |
364 /// Returns a single-subscription stream that emits the results of [operations] | 369 /// Returns a single-subscription stream that emits the results of [operations] |
365 /// in the order they complete. | 370 /// in the order they complete. |
366 /// | 371 /// |
367 /// If the subscription is canceled, any pending operations are canceled as | 372 /// If the subscription is canceled, any pending operations are canceled as |
368 /// well. | 373 /// well. |
369 Stream inCompletionOrder(Iterable<CancelableOperation> operations) { | 374 Stream inCompletionOrder(Iterable<CancelableOperation> operations) { |
370 var operationSet = operations.toSet(); | 375 var operationSet = operations.toSet(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 urlSafe: urlSafe, addLineSeparator: addLineSeparator); | 421 urlSafe: urlSafe, addLineSeparator: addLineSeparator); |
417 } | 422 } |
418 | 423 |
419 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. | 424 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. |
420 shelf.Middleware nestingMiddleware(String beneath) { | 425 shelf.Middleware nestingMiddleware(String beneath) { |
421 return (handler) { | 426 return (handler) { |
422 var pathHandler = new PathHandler()..add(beneath, handler); | 427 var pathHandler = new PathHandler()..add(beneath, handler); |
423 return pathHandler.handler; | 428 return pathHandler.handler; |
424 }; | 429 }; |
425 } | 430 } |
OLD | NEW |