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

Side by Side Diff: sdk/lib/async/future_impl.dart

Issue 11833032: Fix pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/archive/input_stream.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 part of dart.async; 5 part of dart.async;
6 6
7 deprecatedFutureValue(_FutureImpl future) => 7 deprecatedFutureValue(_FutureImpl future) =>
8 future._isComplete ? future._resultOrListeners : null; 8 future._isComplete ? future._resultOrListeners : null;
9 9
10 10
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 class _WhenFuture<T> extends _TransformFuture<T, T> { 413 class _WhenFuture<T> extends _TransformFuture<T, T> {
414 final _FutureAction _action; 414 final _FutureAction _action;
415 415
416 _WhenFuture(this._action); 416 _WhenFuture(this._action);
417 417
418 void _sendValue(T value) { 418 void _sendValue(T value) {
419 try { 419 try {
420 var result = _action(); 420 var result = _action();
421 if (result is Future) { 421 if (result is Future) {
422 Future resultFuture = result; 422 Future resultFuture = result;
423 result.then((_) { 423 resultFuture.then((_) {
424 _setValue(value); 424 _setValue(value);
425 }, onError: (AsyncError e) { 425 }, onError: _setError);
426 _setError(e);
427 });
428 return; 426 return;
429 } 427 }
430 } catch (e, s) { 428 } catch (e, s) {
431 _setError(new AsyncError(e, s)); 429 _setError(new AsyncError(e, s));
432 return; 430 return;
433 } 431 }
432
434 _setValue(value); 433 _setValue(value);
435 } 434 }
436 435
437 void _sendError(AsyncError error) { 436 void _sendError(AsyncError error) {
438 try { 437 try {
439 var result = _action(); 438 var result = _action();
440 if (result is Future) { 439 if (result is Future) {
441 Future resultFuture = result; 440 Future resultFuture = result;
442 result.then((_) { 441 // TODO(lrn): Find a way to combine [error] into [e].
442 resultFuture.then((_) {
443 _setError(error); 443 _setError(error);
444 }, onError: (AsyncError e) { 444 }, onError: _setError);
445 // TODO(lrn): Find a way to combine error into the
446 // resulting error.
447 _setError(e);
448 });
449 return; 445 return;
450 } 446 }
451 } catch (e, s) { 447 } catch (e, s) {
452 error = new AsyncError.withCause(e, s, error); 448 error = new AsyncError.withCause(e, s, error);
453 } 449 }
454 _setError(error); 450 _setError(error);
455 } 451 }
456 } 452 }
457 453
458 /** 454 /**
459 * Thin wrapper around a [Future]. 455 * Thin wrapper around a [Future].
460 * 456 *
461 * This is used to return a "new" [Future] that effectively work just 457 * This is used to return a "new" [Future] that effectively work just
462 * as an existing [Future], without making this discoverable by comparing 458 * as an existing [Future], without making this discoverable by comparing
463 * identities. 459 * identities.
464 */ 460 */
465 class _FutureWrapper<T> implements Future<T> { 461 class _FutureWrapper<T> implements Future<T> {
466 final Future<T> _future; 462 final Future<T> _future;
467 463
468 _FutureWrapper(this._future); 464 _FutureWrapper(this._future);
469 465
470 Future then(function(T value), { onError(AsyncError error) }) { 466 Future then(function(T value), { onError(AsyncError error) }) {
471 return _future.then(function, onError: onError); 467 return _future.then(function, onError: onError);
472 } 468 }
473 469
474 Future catchError(function(AsyncError error), {bool test(var error)}) { 470 Future catchError(function(AsyncError error), {bool test(var error)}) {
475 return _future.catchError(function, test: test); 471 return _future.catchError(function, test: test);
476 } 472 }
477 473
478 Future whenComplete(action()) { 474 Future<T> whenComplete(action()) {
479 return _future.whenComplete(action); 475 return _future.whenComplete(action);
480 } 476 }
481 477
482 Stream<T> asStream() => new Stream.fromFuture(this); 478 Stream<T> asStream() => new Stream.fromFuture(_future);
483 } 479 }
OLDNEW
« no previous file with comments | « no previous file | utils/archive/input_stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698