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

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

Issue 94843002: Unify dart:async and pub/io.dart TimeoutException classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years 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 | « sdk/lib/async/future.dart ('k') | 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) 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 /** The onValue and onError handlers return either a value or a future */ 7 /** The onValue and onError handlers return either a value or a future */
8 typedef dynamic _FutureOnValue<T>(T value); 8 typedef dynamic _FutureOnValue<T>(T value);
9 /** Test used by [Future.catchError] to handle skip some errors. */ 9 /** Test used by [Future.catchError] to handle skip some errors. */
10 typedef bool _FutureErrorTest(var error); 10 typedef bool _FutureErrorTest(var error);
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 source = listener; 537 source = listener;
538 } 538 }
539 } 539 }
540 540
541 Future timeout(Duration timeLimit, {void onTimeout()}) { 541 Future timeout(Duration timeLimit, {void onTimeout()}) {
542 if (_isComplete) return new _Future.immediate(this); 542 if (_isComplete) return new _Future.immediate(this);
543 _Future result = new _Future(); 543 _Future result = new _Future();
544 Timer timer; 544 Timer timer;
545 if (onTimeout == null) { 545 if (onTimeout == null) {
546 timer = new Timer(timeLimit, () { 546 timer = new Timer(timeLimit, () {
547 result._completeError(new TimeoutException(timeLimit)); 547 result._completeError(new TimeoutException("Future not completed",
548 timeLimit));
548 }); 549 });
549 } else { 550 } else {
550 Zone zone = Zone.current; 551 Zone zone = Zone.current;
551 onTimeout = zone.registerCallback(onTimeout); 552 onTimeout = zone.registerCallback(onTimeout);
552 timer = new Timer(timeLimit, () { 553 timer = new Timer(timeLimit, () {
553 try { 554 try {
554 result._complete(zone.run(onTimeout)); 555 result._complete(zone.run(onTimeout));
555 } catch (e, s) { 556 } catch (e, s) {
556 result._completeError(e, s); 557 result._completeError(e, s);
557 } 558 }
558 }); 559 });
559 } 560 }
560 this.then((T v) { 561 this.then((T v) {
561 if (timer.isActive) { 562 if (timer.isActive) {
562 timer.cancel(); 563 timer.cancel();
563 result._complete(v); 564 result._complete(v);
564 } 565 }
565 }, onError: (e, s) { 566 }, onError: (e, s) {
566 if (timer.isActive) { 567 if (timer.isActive) {
567 timer.cancel(); 568 timer.cancel();
568 result._completeError(e, s); 569 result._completeError(e, s);
569 } 570 }
570 }); 571 });
571 return result; 572 return result;
572 } 573 }
573 } 574 }
OLDNEW
« no previous file with comments | « sdk/lib/async/future.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698