OLD | NEW |
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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 result._setValue(listenerValueOrError); | 673 result._setValue(listenerValueOrError); |
674 } else { | 674 } else { |
675 AsyncError asyncError = listenerValueOrError; | 675 AsyncError asyncError = listenerValueOrError; |
676 result._setErrorObject(asyncError); | 676 result._setErrorObject(asyncError); |
677 } | 677 } |
678 // Prepare for next round. | 678 // Prepare for next round. |
679 source = result; | 679 source = result; |
680 } | 680 } |
681 } | 681 } |
682 | 682 |
683 Future timeout(Duration timeLimit, {onTimeout()}) { | 683 Future<T> timeout(Duration timeLimit, {onTimeout()}) { |
684 if (_isComplete) return new _Future.immediate(this); | 684 if (_isComplete) return new _Future.immediate(this); |
685 _Future result = new _Future(); | 685 _Future result = new _Future<T>(); |
686 Timer timer; | 686 Timer timer; |
687 if (onTimeout == null) { | 687 if (onTimeout == null) { |
688 timer = new Timer(timeLimit, () { | 688 timer = new Timer(timeLimit, () { |
689 result._completeError(new TimeoutException("Future not completed", | 689 result._completeError(new TimeoutException("Future not completed", |
690 timeLimit)); | 690 timeLimit)); |
691 }); | 691 }); |
692 } else { | 692 } else { |
693 Zone zone = Zone.current; | 693 Zone zone = Zone.current; |
694 onTimeout = zone.registerCallback(onTimeout); | 694 onTimeout = zone.registerCallback(onTimeout); |
695 timer = new Timer(timeLimit, () { | 695 timer = new Timer(timeLimit, () { |
(...skipping 11 matching lines...) Expand all Loading... |
707 } | 707 } |
708 }, onError: (e, s) { | 708 }, onError: (e, s) { |
709 if (timer.isActive) { | 709 if (timer.isActive) { |
710 timer.cancel(); | 710 timer.cancel(); |
711 result._completeError(e, s); | 711 result._completeError(e, s); |
712 } | 712 } |
713 }); | 713 }); |
714 return result; | 714 return result; |
715 } | 715 } |
716 } | 716 } |
OLD | NEW |